gpt4 book ai didi

javascript - i 和 0 在这里做什么?有人可以解释吗?

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

我正在接受代码大战的挑战,我正在寻找解决方案,但我不理解它。有人能像 o 一样解释 s 的作用吗?

function duplicateEncode(word) {
word = word.toLowerCase();
var c = '', s = '', o = '';

for (i = 0; i < word.length; i++) {
s = word.slice(i + 1);
o = s + word.slice(0, i);
c += (o.indexOf(word[i]) > -1) ? ')' : '(';
}

return c;
}

最佳答案

来自 String.prototype.slice MDN documentation :

beginIndex

The zero-based index at which to begin extraction. If negative, it is treated as strLength + (beginIndex) where strLength is the length of the string (for example, if beginIndex is -3 it is treated as strLength - 3). If beginIndex is greater than or equal to the length of the string, slice() returns an empty string.

endIndex

Optional. The zero-based index before which to end extraction. The character at this index will not be included. If endIndex is omitted, slice() extracts to the end of the string. If negative, it is treated as strLength + endIndex where strLength is the length of the string (for example, if endIndex is -3 it is treated as strLength - 3).

关于javascript - i 和 0 在这里做什么?有人可以解释吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57697172/

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