Skip to content

Commit 1b6cc9b

Browse files
committed
Refactor includes implementation to use for...of loop
1 parent 96d077b commit 1b6cc9b

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

Sprint-1/refactor/includes.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
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+
// Loop through each element in the list using a for...of loop
5+
for (const element of list) {
6+
// If the current element matches the target, return true
67
if (element === target) {
78
return true;
89
}
910
}
11+
12+
// If the loop finishes without finding the target, return false
1013
return false;
1114
}
1215

0 commit comments

Comments
 (0)