count
ループがあり、パターン内の特定の数値を trueとして返す必要があり4
ます4-1(3)
。5、12、19、26、33 などを true として返し、その他を false として返す必要があります。
function saturn(count,perline){
var line_one = perline; // 5
var line_two = perline-1; // 4
var line_both = line_one + line_two; // 7
var x = (perline+1)+(line_both*(Math.floor(count/(perline+1))-1));
if(x<0) x = 0;
var capture;
if(perline == 1){ //if perline = 1 don't indent any
capture = false;
}else if(x == count){
capture = true;
}
console.log("("+perline+"+1)+("+line_both+"*(Math.floor("+count+"/("+perline+"+1))-1)) ="+x);
console.log(count+" "+capture);
return capture;
}
コンソール出力。
script.js:54(4+1)+(7*(Math.floor(1/(4+1))-1)) =0
script.js:561 undefined
script.js:54(4+1)+(7*(Math.floor(2/(4+1))-1)) =0
script.js:562 undefined
script.js:54(4+1)+(7*(Math.floor(3/(4+1))-1)) =0
script.js:563 undefined
script.js:54(4+1)+(7*(Math.floor(4/(4+1))-1)) =0
script.js:564 undefined
script.js:54(4+1)+(7*(Math.floor(5/(4+1))-1)) =5
script.js:565 true
script.js:54(4+1)+(7*(Math.floor(6/(4+1))-1)) =5
script.js:566 undefined
script.js:54(4+1)+(7*(Math.floor(7/(4+1))-1)) =5
script.js:567 undefined
script.js:54(4+1)+(7*(Math.floor(8/(4+1))-1)) =5
script.js:568 undefined
script.js:54(4+1)+(7*(Math.floor(9/(4+1))-1)) =5
script.js:569 undefined
script.js:54(4+1)+(7*(Math.floor(10/(4+1))-1)) =12
script.js:5610 undefined
script.js:54(4+1)+(7*(Math.floor(11/(4+1))-1)) =12
script.js:5611 undefined
script.js:54(4+1)+(7*(Math.floor(12/(4+1))-1)) =12
script.js:5612 true
script.js:54(4+1)+(7*(Math.floor(13/(4+1))-1)) =12
script.js:5613 undefined
script.js:54(4+1)+(7*(Math.floor(14/(4+1))-1)) =12
script.js:5614 undefined
script.js:54(4+1)+(7*(Math.floor(15/(4+1))-1)) =19
script.js:5615 undefined
script.js:54(4+1)+(7*(Math.floor(16/(4+1))-1)) =19
script.js:5616 undefined
script.js:54(4+1)+(7*(Math.floor(17/(4+1))-1)) =19
script.js:5617 undefined
script.js:54(4+1)+(7*(Math.floor(18/(4+1))-1)) =19
script.js:5618 undefined
script.js:54(4+1)+(7*(Math.floor(19/(4+1))-1)) =19
script.js:5619 true
script.js:54(4+1)+(7*(Math.floor(20/(4+1))-1)) =26
script.js:5620 undefined
script.js:54(4+1)+(7*(Math.floor(21/(4+1))-1)) =26
script.js:5621 undefined
script.js:54(4+1)+(7*(Math.floor(22/(4+1))-1)) =26
script.js:5622 undefined
script.js:54(4+1)+(7*(Math.floor(23/(4+1))-1)) =26
script.js:5623 undefined
script.js:54(4+1)+(7*(Math.floor(24/(4+1))-1)) =26
script.js:5624 undefined
script.js:54(4+1)+(7*(Math.floor(25/(4+1))-1)) =33
script.js:5625 undefined
script.js:54(4+1)+(7*(Math.floor(26/(4+1))-1)) =33
script.js:5626 undefined
script.js:54(4+1)+(7*(Math.floor(27/(4+1))-1)) =33
script.js:5627 undefined
script.js:54(4+1)+(7*(Math.floor(28/(4+1))-1)) =33
script.js:5628 undefined