I have some objects into an array. I want to compare object[0].position with object[1].position and If These two values were equal, object[0].position = 0. how can I do this?
`
function carInfo(name) {
this.name = name;
this.position = 0;
}
let numOfCars = +prompt("Enter Number of Cars: ");
for (let i = 0; i < numOfCars; i++) {
carNames.push(new carInfo(prompt(`Enter Name of Car No.${i + 1} : `)));
}
let str = "*";
str += str.repeat(300);
console.log(str);
function shuffleArray(array) {
for (let i = 0; i < array.length; i++) {
let temp = Math.floor(Math.random() * 10 + 1);
array[i].position += temp;
if (array[i].position >= 300) {
alert("game end! " + '"' + array[i].name + '"' + " win");
break;
}
}
return array;
}
`
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…