"Write a function which counts the number of a's in the input string."
"We will give you an array of words. Print out each word which appears more than 3 times in the array."
"We will give you two arrays of words. Print out each word which is in exactly one of the arrays."
It's not just the mod operator. These are toy problems for difficulty but they're not "implement the rules to a children's game"; with a few seconds of effort you can describe a boringly plausible business reason for having to implement them during a fairly pedestrian career.
The goal of fizzbuzz in a phone screen should not be to see if someone can solve it in an optimal memory-efficient framework-idiomatic way. Clever syntax and data structure use is lovely, but these are really about finding whether someone can use a 'for' loop and an 'if' condition.
If the test is interactive, the candidate can express, "I need to find out if this number is evenly divisible by that number; if so, then blah blah". Interviewer can remind them that x % 2 is "remainder of x when it is divided by 2". The point should not be whether someone can remember %, but whether they have any idea what minor goal they are trying to achieve.
Even if you (somehow) don't know about it, figure something out? Do something "stupid that works" like this:
def floatcheck(x:Float, div:Int): String = (x / div).toString.split("\\.")(1) match {
case "0" => "int"
case _ => "float"
}
(1 until 100).foreach(e => {
if(floatcheck(e,15) == "int") println("fizzbuzz")
else if(floatcheck(e,3) == "int") println("fizz")
else if(floatcheck(e,5) == "int") println("buzz")
else println(e)
})
(I'm guessing this works, or maybe I fall into that category as well ;))You are being tested on finding a solution that works, not on what function you use.
I had to learn C at some point though, and that used to be common. I suppose it's becoming a less useful test.