I'm learning JS and I came across a challenge and I'm curious regarding why the "break;" is needed for this function to work. I though it was only needed in Switch loops. Thanks in advance!
_.some = function (collection, predicate, context) {
let result = false;
for (let i in collection) {
if (context) {
if (predicate.call(context, collection[i], i, collection)) {
result = true;
break;
}
}
if (collection.hasOwnProperty(i)) {
if (predicate(collection[i], i, collection)) {
result = true;
break;
} else result = false;
}
}
return result;
};