gpt4 book ai didi

javascript - 第一个字 第一个字符 第二个字 第二个字符 一直到数组末尾

转载 作者:行者123 更新时间:2023-11-28 07:28:05 28 4
gpt4 key购买 nike

 words = [
"January",
"lacks",
"caveats",
"hazardous",
"DOORS",
"crying",
"arrogantly",
"climate",
"proponent",
"rebuttal"
]; // answer Has to be JavaScript
// i can only get it right till JavaS

function decode(words){

for(i=0;i<words.length;i++){
msg = words[i].charAt(i);

while(i>6 && i<=words.length){
j=0;
msg = words[i].charAt(j);
j++;
}
console.log(msg);
}


}
decode(words);

J
a
v
a
S
g
n

t

对于第一个单词,抓取第一个字符,对于第二个单词,抓取第二个字符,依此类推。当您到达第 6 个单词时,再次从第一个字符开始。

最佳答案

% 给出 i 除以 5 的余数。
0%5 = 0、1%5 = 1、...、5%5 = 0 等等..

function decode(words){
for(i=0;i<words.length;i++){
msg = words[i].charAt(i%5);
console.log(msg);
}
}

关于javascript - 第一个字 第一个字符 第二个字 第二个字符 一直到数组末尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29423685/

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