The slice() method returns a shallow copy of a portion of
an array into a new array object selected from start to end
(end not included) where start and end represent
the index of items in that array. The original array will not be modified.
Tech Lead/Team Lead. Senior WebDev.
Intermediate Grade on Computer Systems-
High Grade on Web Application Development-
MBA (+Marketing+HHRR).
Studied a bit of law, economics and design
Location
Spain
Education
Higher Level Education Certificate on Web Application Development
return
arr.slice(d).concat(arr.slice(0, d))
is enoughThank you i will try this
Can you please explain this code?
I am getting a bit confused with it
Better?
Array.prototype.slice() - JavaScript | MDN
The slice() method returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array. The original array will not be modified.
Got it thank you for explaining 😉
Also
Number.parseInt(arr.length % d)
could be useful in case the number is greater than the arr length.With that you can simply do a single complete rotation and keeo going the extra steps instead of failing 😁
Thank you i will try this as well 😉