You are viewing a single comment's thread. Return to all comments →
Scala recursive solution with pattern matching and list concatenation:
def f(arr:List[Int]):List[Int] = { def newArrayThing(oldOne:List[Int], newOne:List[Int]): List[Int] = oldOne match { case x::xs => if (x < 0) newArrayThing(xs, newOne:+(-x)) else newArrayThing(xs, newOne:+x) case Nil => newOne } newArrayThing(arr, List()) }
Seems like cookies are disabled on this browser, please enable them to open this website
Update List
You are viewing a single comment's thread. Return to all comments →
Scala recursive solution with pattern matching and list concatenation: