Find the Bug in my Fizz Buzz Interview (2:47 video)
edweissman.com
edweissman.com
var result = "";
and checks for: if (result.length === 0) {
...
in the third conditional, is there still a bug?Forcing anyone to do a coding exercise in their head is ridiculous.
He goes on to append strings to this variable which would lead me to believe it has some value that you can append to.
This would make the third conditional where he checks for null to fail, he should check for an empty string.
fizzbuzz = (1..100).to_a.map do |i|
result = "" # 1:23 initialize a variable
result += "Fizz" if i % 3 == 0
result += "Buzz" if i % 5 == 0
result = i.to_s if result.nil?
result
end
The corrected solution would be to change `result.nil?` to `result.empty?`, i.e. checking for "empty string" instead of "null".He doesn't ever print out result either
PS : My assumption is that you need to print each number or Fizz or Buzz or FizzBuzz in a separate line.