Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

b) Write a tail-recursive polymorphic function with this signature: def countWitheconectx[T](X$: List[T], p: T => Boolean) : Int that returns the number of elements x

image text in transcribed

b) Write a tail-recursive polymorphic function with this signature: def countWitheconectx[T](X$: List[T], p: T => Boolean) : Int that returns the number of elements x from list xs for which p(x) is true. For example: xal lucky Numbers = List(4, 8, 15, 16, 23, 42) val evenCount = countWithProperty (lucky Numbers, (x: Int) => x % 2 == 0) The value of variable evenCount is 4. c) Write a tail-recursive function with this signature: def scalare.reduct(x: Array[Double], y: Array[Double]) : Double that returns the scalar product of arrays x and y. For example: xal xxes = Array(-1.0, -2, 3) val xxes = Array(2.0, -3, 1) xal prod = scalarproduct(xvec, yves) = // prod == 7 b) Write a tail-recursive polymorphic function with this signature: def countWitheconectx[T](X$: List[T], p: T => Boolean) : Int that returns the number of elements x from list xs for which p(x) is true. For example: xal lucky Numbers = List(4, 8, 15, 16, 23, 42) val evenCount = countWithProperty (lucky Numbers, (x: Int) => x % 2 == 0) The value of variable evenCount is 4. c) Write a tail-recursive function with this signature: def scalare.reduct(x: Array[Double], y: Array[Double]) : Double that returns the scalar product of arrays x and y. For example: xal xxes = Array(-1.0, -2, 3) val xxes = Array(2.0, -3, 1) xal prod = scalarproduct(xvec, yves) = // prod == 7

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 11g SQL

Authors: Jason Price

1st Edition

0071498508, 978-0071498500

More Books

Students also viewed these Databases questions