寻找一种更简洁的方法来编写这个 for 循环。我打算使用 continue; 并意识到 .forEach 不喜欢这种语法。const findNoOptions = array => { let str = ""; for (let i = 1; ; i += 1) { str = "Z".repeat(i); let found = false; array.forEach(element => { if (element.toUpperCase().includes(str)) { found = true; } }); if (!found) { break; } }};
2 回答
![?](http://img1.sycdn.imooc.com/5458478b0001f01502200220-100-100.jpg)
慕婉清6462132
TA贡献1804条经验 获得超2个赞
也许是这样的
const findNoOptions = array => {
let str = "";
while(true) {
str += "Z";
let found = array.some(el => el.toUpperCase().includes(str))
if (!found) break;
}
};
![?](http://img1.sycdn.imooc.com/54586431000103bb02200220-100-100.jpg)
炎炎设计
TA贡献1808条经验 获得超4个赞
而不是使用休息你可以做
const findNoOptions = array => {
let str = "";
while(array.some(el => el.toUpperCase().includes(str))) {
str += "Z";
}
};
添加回答
举报
0/150
提交
取消