Shuffle array and shuffle Selected Index

PHOTO EMBED

Thu Apr 08 2021 10:16:24 GMT+0000 (Coordinated Universal Time)

Saved by @thepuskar #javascript #array #shuffle

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)
content_copyCOPY

https://playcode.io/754960/