I'm working on developing a function that can generate a random number between 0 and 9 that is not already included in an array.
Here is the code I have come up with so far:
var myArr = [0,2,3,4];
console.log("Array: " + myArr);
function newNumber(){
console.log("testing");
for (var i = 0; i < 10; i++) {
var n = myArr.includes(i)
// I am aiming to only return 'n' if it is not already present in the array
}
return n;
}
newNumber()
I am looking to return a single unique number. Can someone guide me on how I can achieve this?
Appreciate the assistance.