I don't know if it's the best way I'm implementing it, what I can't do is that pressing the block button only allows randomizing (shuffling) the elements that are not blocked, I tried several ways that doesn't work, for example, when i pressed the locked button, it saved the id and then compare, but i couldn't do it.
// this array, button locked
const dataId = ["b79bc2a0-da09-4620-9b3d-1ed32d697f0a", "a60d0c77-439d-4764-b115-f4c24f857cd1"];
const data =[
{
id: "b79bc2a0-da09-4620-9b3d-1ed32d697f0a"
name: "three"
email: "three@gmail.com"
},
{
id: "c8648167-3103-44f9-b03c-3bd951fb339c"
name: "two"
email: "two@gmail.com"
},
{
id: "a60d0c77-439d-4764-b115-f4c24f857cd1"
name: "one"
email: "one@gmail.com"
}
];
function shuffle(array) {
let currentIndex = array.length,
randomIndex;
// While there remain elements to shuffle.
while (currentIndex !== 0) {
// Pick a remaining element.
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex--;
// And swap it with the current element.
[array[currentIndex], array[randomIndex]] = [
array[randomIndex],
array[currentIndex]
];
}
return array;
}
let locked = [];
data.filter(
(d: IList) => !dataId.includes(d.id) && locked.push(d)
);
const data = shuffle(locked);
As you can see, what I was doing is not right and I can't think of how to implement it. Is it possible to do something like what I am implementing?
any information you need please let me know