Skip to content

Commit 784cfd2

Browse files
committed
Refactor includes.js to use for...of loop
1 parent 9455a47 commit 784cfd2

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

Sprint-1/refactor/includes.js

Lines changed: 5 additions & 3 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];
6-
if (element === target) {
4+
if (!Array.isArray(list)) return false;
5+
6+
for (const item of list) {
7+
if (item === target) {
78
return true;
89
}
910
}
11+
1012
return false;
1113
}
1214

0 commit comments

Comments
 (0)