判定するdecision関数を最適化したいです。
いい方法はないですか?
javaScript
1 2const min = 1 3const max = 100 4 5//計算式 6let remainder = function(array,f) { 7 return array.map(f) 8} 9 10//判定 11let decision = function(s){ 12 13 if (s % 15 == 0) { 14 return "FizzBuzz" 15 } else if (s % 3 == 0) { 16 return "Fizz" 17 } else if (s % 5 == 0) { 18 return "Buzz" 19 } else { 20 return s 21 } 22} 23 24//数値の生成 25let renge = function(min,max) { 26 return [...Array(max - min + 1).keys()].map(x => x + min) 27 28} 29 30//物質化 31let answer = remainder(renge(min,max),decision) 32 33//出力 34console.log(answer) 35 36
回答5件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。