gpt4 book ai didi

javascript - 循环返回 bool 值

转载 作者:行者123 更新时间:2023-11-30 18:27:46 25 4
gpt4 key购买 nike

我有一个循环,我需要返回一个模式中的某些数字为 true 我有 count 以及数字 4 4-1(3)。我需要返回 5、12、19、26、33 等为真,其他为假。

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

最佳答案

这就是你想要做的?

return (x - 5) % 7 == 0

它为 5、12、19、26 和 33 返回 true。

EDIT:你已经编辑过了,我还是不明白你说的是什么,但这没有用,抱歉

关于javascript - 循环返回 bool 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10400766/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com