Skip to content

Commit 7866c4b

Browse files
committed
Refactor includes to use for...of loop
1 parent 68cee2e commit 7866c4b

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

Sprint-1/refactor/includes.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// Refactor the implementation of includes to use a for...of loop
22

33
function includes(list, target) {
4-
for (let index = 0; index < list.length; index++) {
5-
const element = list[index];
4+
// Iterate directly over each element in the list
5+
for (const element of list) {
6+
// Return true as soon as we find a match
67
if (element === target) {
78
return true;
89
}
910
}
11+
// Target was not found in the list
1012
return false;
1113
}
1214

0 commit comments

Comments
 (0)