Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In the following problems do not use any mutable variables (i.e., variables decl

ID: 3887905 • Letter: I

Question

In the following problems do not use any mutable variables (i.e., variables declared with var) or any mutable predened types such as arrays, mutable sets, and so on. You may dene methods recursively this time. Do not use the if operator in Problems 1-4 below.

3. Write a Scala method isIn (x: Int, l: List[Int]): Boolean which, given an integer value x and an integer list l, returns true if and only if x is an element of l. Do not use the contains method or similar methods of the List class or any other class.

Explanation / Answer

Hi, Please find my implementation.

def isIn (x: Int, l: List[Int]): Boolean = {

l.foreach(ele => if(ele == x) return true)
false // not found
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote