gpt4 book ai didi

javascript 旋转数组元素

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

<分区>

大家好,我有这个任务:我有一个数组 [4,7,3,6,9],我必须像这样创建一个数组:

[4,7,3,6,9]
[9,4,7,3,6]
[6,9,4,7,3]
[3,6,9,4,7]
[7,3,6,9,4]

我必须制作一个数组旋转的程序,即使我向数组添加一个新项目它也应该相应地改变。我是 JS 的新手,1 周左右,这是我目前的尝试:

var numbers = [4, 7, 3, 6, 9];
console.log(numbers);
numbers[0] = 9; numbers[1] = 4; numbers[2] = 7; numbers[3] = 3; numbers[4] = 6;
console.log(numbers);
numbers[0] = 6; numbers[1] = 9; numbers[2] = 4; numbers[3] = 7; numbers[4] = 3;
console.log(numbers);
numbers[0] = 3; numbers[1] = 6; numbers[2] = 9; numbers[3] = 4; numbers[4] = 7;
console.log(numbers);
numbers[0] = 7; numbers[1] = 3; numbers[2] = 6; numbers[3] = 9; numbers[4] = 4;
console.log(numbers);

我也有 .push、.splice 等。我不知道为什么,但我真的觉得 javascript 不适合我的大脑,哈哈 :D

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