Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Must be written in Scala PLEASE Write a recursive function filterNumList(1: Numlist, f: Int - Boolean): Numlist that takes in a Numlist and a function
Must be written in Scala PLEASE
Write a recursive function filterNumList(1: Numlist, f: Int - Boolean): Numlist that takes in a Numlist and a function f: Int - Boolean 1. It should retum a new list that consist of all elements of the list l that return true when the function f is ca ed on them. 2. The returned list elements must preserve the same order as in the original list. YOUR CODE HERE filterNumList(1: NumList, f: Int Boolean): NumListi val 11 Cons(12, Cons(25, Cons(37, Nil))) def f1(j: Int): Booleanj 25 && j12 val 12 Cons (22, Cons (135, Cons (137, 11))) def f2(j: Int): Boolean j % 5 :: assert( filter-NumLst(12, f2) :: Cons(135, Cons(25, Nil)), "Test 2 failed." def f3(j: Int): Booleanj210 assert(filterNumLst(12, f3) Nil, "Test 3 failed assert(filterNumList(Nil, f3) :: N, "Test 4 failed.") def f4(j: Int): Boolean : jStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started