Skip to content

Instantly share code, notes, and snippets.

@monjudoh
Created August 9, 2012 10:44
Show Gist options
  • Save monjudoh/3303195 to your computer and use it in GitHub Desktop.
Save monjudoh/3303195 to your computer and use it in GitHub Desktop.
JSでFizzBuzz。剰余と一切の条件分岐を無くしたよ。さらに、元々ループと再帰はなかったけど、反復メソッドも(見かけ上)なくしたよ。
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';
});
@monjudoh
Copy link
Author

短くしたがString#replaceに正規表現と関数を渡した場合の動作が実質反復メソッドだと示しているだけかも

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment