This code works, but it returns the answer 15 twice. Is there a way to break out once it's been met the first time?
let input = "2 3 4 4 4 5 6 10 8";
let nums = input.split(" ").map(x => parseInt(x));
for(let i = 0; i < nums.length; i++){
let first = nums[i];
for(let j = 0; j < nums.length; j++){
let second = nums[j];
if(first + second === 15){
console.log(first * second);
}
}
}
Aucun commentaire:
Enregistrer un commentaire