let items = [1,25,"JavaScript",69,"css","34","keep coding","html"];
console.log(items)
//shuffle array
function shuffle(arr){
for(let i =arr.length-1;i>0;i--){
const j = Math.floor(Math.random() * (i+1));
[arr[i],arr[j]] = [arr[j],arr[i]];
}
return arr
}
console.log(shuffle(items))
//shuffle selected index
const itemToShuffle = items.slice(3,7);
console.log(shuffle(itemToShuffle))
//items after shuffling item from index 3 to 7
items = [items[0],items[1],items[2],...itemToShuffle,items[7]]
console.log(items)
Comments