This is a simplified example, but say I want to generate 5 unique positions on a 100x100 grid. These positions will be stored in an array [[x, y], ...].
The tried the obvious method of generating a random x and y and checking to see if the array [x, y] is already in the result array. If it is, generate different values, if not add it to the result array.
result = [];
while (result.length !== 5) {
let x = Math.floor(Math.random() * 100) + 1;
let y = Math.floor(Math.random() * 100) + 1;
if (!result.includes([x, y])) {
result.push(array);
}
}
However, this will never find the duplicates, as the arrays are technically different objects. So, what is the preferred method for detecting if an array contains an 'equal' array/object?