Question: d) Write a tail-recursive polymorphic function with this signature: def count Common Elements[T](xs: Array[T], xs: Array[T], P: (T, T) => Boolean): Int that returns the

 d) Write a tail-recursive polymorphic function with this signature: def count

d) Write a tail-recursive polymorphic function with this signature: def count Common Elements[T](xs: Array[T], xs: Array[T], P: (T, T) => Boolean): Int that returns the number of elements x in Xs and y in ys, such that p(x, y) is true. This can be used, for example, to count the number of elements in Xs that are also in ve val as = Array(7,3, 8, 4, 9, 3, 5) val bs = Array(8, -4, 5, 1, 0, 2, 4) val commenNumbers = countcommon Elements(as, bs, (x: Int, y: Int) => x == y) // common Numbers == 3, for 8, 5, 4 are both in as and bs a e) Write a main function in object p3 that illustrates how to use the above functions with anonymous functions. Do not use the example code given in parts a)-d)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!