How do you efficiently scroll an array with looping either acting on the array itself or returning a new array
arr = [1,2,3,4,5]
i want to do something like this:
arr.scroll(-2)
arr now is [4,5,1,2,3]
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use
Array.slice:You can then generalize it and extend
Array.prototypewith thescrollfunction: