Created
August 9, 2012 10:44
-
-
Save monjudoh/3303195 to your computer and use it in GitHub Desktop.
JSでFizzBuzz。剰余と一切の条件分岐を無くしたよ。さらに、元々ループと再帰はなかったけど、反復メソッドも(見かけ上)なくしたよ。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fizzArray = []; | |
buzzArray = []; | |
new Array(101).join('a').replace(/a/g,function(n,i){ | |
fizzArray = fizzArray.concat(['','','Fizz']); | |
buzzArray = buzzArray.concat(['','','','','Buzz']); | |
var result = (fizzArray[i]+buzzArray[i]).replace(/^$/,i + 1); | |
return result + '\n'; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
短くしたがString#replaceに正規表現と関数を渡した場合の動作が実質反復メソッドだと示しているだけかも