Skip to content

Commit 1485358

Browse files
committed
refactered code within includes function to use for of loop
1 parent 8b56981 commit 1485358

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

Sprint-1/refactor/includes.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
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];
6-
if (element === target) {
4+
for (let item of list) {
5+
if (target === item) {
76
return true;
87
}
98
}
109
return false;
1110
}
12-
11+
console.log(includes(["a", "b", "c", "d"], "c"));
1312
module.exports = includes;

0 commit comments

Comments
 (0)