Question d’entretien chez Ignite Solutions

Write a function that takes an array of integers and returns that array rotated by N positions using Python or Ruby or JavaScript. For example, if N=2, given the input array [1, 2, 3, 4, 5, 6] the function should return [5, 6, 1, 2, 3, 4]

Réponse à la question d'entretien

Utilisateur anonyme

6 mars 2020

function rotate(array, stepsToShift) { for (var i = 0; i < stepsToShift; i++) { array.unshift(array.pop()); } return array; } arr = [1,2,3,4,5,6] print(rotate(arr,3))