3 ms·
I wonder what would happen if you gave the interviewer a piece of code that's not familiar to him, e.g... val translation = List(3 -> "Fizz", 5 -> "Buzz")
by bad_user 14y ago
I wonder what would happen if you gave the interviewer a piece of code that's not familiar to him, e.g...
val translation = List(3 -> "Fizz", 5 -> "Buzz")
val numbers = {
def start(from: Int): Stream[Int] =
from #:: start(from+1)
start(1)
}
val fizzbuzz = numbers.map(nr =>
translation.collect {
case (k,value) if nr % k == 0 =>
value
}
.reduceLeftOption(_+_)
.getOrElse(nr.toString))
println( fizzbuzz.take(100).mkString("\n") )
- jlgreco 14y agoIf the interviewer were good, they would play it cool and immediately ask the candidate to walk through the code out-loud and give reasons that they did what they did.