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: 3887672 • 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.

2. Write a Scala method concatAll (l: List[String]):String which, given any list l of strings, returns the concatenation of all the strings in l. For example, concatAll(List("un", "be", "liev", "a", "ble")) is ”unbelievable”.

Note that in Scala "" is the empty string and ++ is the inx concatenation operator for strings.

Explanation / Answer

object MyClass {
     def concatAll(l: List[String]) = l.mkString("")
  
     def main(args: Array[String]) {
         print( concatAll(List("un", "be", "liev", "a", "ble")) );
      }
   }

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