We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Scala noob here, any comments if this is a valid solution
scala
def abs(x:Int):Int = {
if(x<0)
x * -1
else
x
}
def f(arr:List[Int]):List[Int] = {
arr.map(x=> abs(x)).toList
}
Cookie support is required to access HackerRank
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 noob here, any comments if this is a valid solution
scala def abs(x:Int):Int = { if(x<0) x * -1 else x } def f(arr:List[Int]):List[Int] = { arr.map(x=> abs(x)).toList
}