-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Open
Labels
Description
因为步数有可能大于数组长度,所以要先取余
function rotate(arr, k) {
const len = arr.length
const step = k % len
return arr.slice(-step).concat(arr.slice(0, len - step))
}
// rotate([1, 2, 3, 4, 5, 6], 7) => [6, 1, 2, 3, 4, 5]
JerryLin233, 5SSS, rocky-191, halionn, Zhou1eezZZ and 112 more1045598742, xiaoqisha, Bellhey, lakalakaka, Molin123 and 8 moreteddy1209 and justsoupGTRgoSkykimliy, Maxfrank, GTRgoSky, xu-code and ysyfffsheng-snd