Skip to content

Commit c6076ed

Browse files
committed
Refactored function to include a for...of loop
1 parent 8323142 commit c6076ed

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Sprint-1/refactor/includes.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +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+
for (let element of list) {
5+
// iterate through each element in the list
66
if (element === target) {
7-
return true;
7+
// check if the current element matches the target
8+
return true; // return true if a match is found and exit the function
89
}
910
}
10-
return false;
11+
return false; // return false if no match is found after checking all elements
1112
}
1213

1314
module.exports = includes;

0 commit comments

Comments
 (0)