FizzBuzzWhizz游戏的js解法
2020-12-13 01:56
标签:style blog class code java tar 5.6休假回来在园子里看到一道比较火的面试题:(链接地址),js解法代码: FizzBuzzWhizz游戏的js解法,搜素材,soscw.com FizzBuzzWhizz游戏的js解法 标签:style blog class code java tar 原文地址:http://www.cnblogs.com/mklp98999/p/3713662.htmlfunction test(a, b, c) {
var s = [false, "Fizz", "Buzz", "FizzBuzz", "Whizz", "FizzWhizz", "BuzzWhizz", "FizzBuzzWhizz"], mod = function(n, a, rv) {return n%a == 0 ? rv : 0;}, result = [];
for(var i=1; i ) {
result[i*10+a -1] = result[a*10+i - 1] = s[1];
}
//开始输出
for(var i = 1, j = 0; i ) {
if (!result[j]) {
var index = mod(i, a, 1) + mod(i, b, 2) + mod(i, c, 4);
result[j] = s[index] ? s[index] : i;
}
}
return result;
}