DEV Community

loading...

Discussion on: Is JavaScript's .shift() Method a Performance Boost?

Collapse
savagepixie profile image
SavagePixie

Well, your proposed solution only shifts the elements one place, while the challenge was to create a function that shifts them an undetermined number of places.

Collapse
aminmansuri profile image
hidden_dude

just change:

let next = (i+1) % a.length

to

let next = (i+offset) % a.length

Where offset is the number of spaces you want to shift.