object Solution { def myAtoi(s: String): Int = { // well, ignores invalid text, instead of returing 0. s.foldRight((0, 1))((v, acc) => v match { case '-' => (acc._1* -1,acc._2) case v if '0' to '9' contains v => (acc._1+(v-'0')*acc._2, acc._2*10) case _ => acc })._1 } }