I tried to solve this challenge, the solution I figured works really well on the console window of Chrome but not in the built in console of the website
function largestOfFour(arr) {
let starter = 0;
let i = 0;
for (i = 0; i < arr.length; i++) {
arr[i].forEach((el) => {
if (el > starter) {
return (starter = el);
}
});
}
arr.forEach((array) => {
if (array.includes(starter)) {
console.log(array);
}
});
}
largestOfFour([
[4, 5, 1, 3],
[13, 27, 18, 26],
[32, 35, 37, 39],
[1000, 1001, 857, 1],
]);
There is no way to stop or break a forEach() loop other than by throwing an exception. If you need such behavior, the forEach() method is the wrong tool.