JSFiddle - React, Tailwind, and code Playground
by Ayan Dey
JavaScript
function solution(A, K) {
// write your code in JavaScript (Node.js 8.9.4)
let aInRange = A.length > 0 && A.length <=100 ? true : false;
let kInRange = K > 0 && K <=100 ? true: false;
let result = [];
if(aInRange && kInRange) {
let newIndex = K;
for(let digit of A) {
if(newIndex >= A.length) {
newIndex = newIndex - A.length;
}
result[newIndex] = digit;
newIndex++
}
}
return result;
}
document.write(solution([3, 8, 9, 7, 6], 3));