Skip to content

Commit 0abc6d8

Browse files
committed
function includes
1 parent bf6d81e commit 0abc6d8

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

Sprint-1/refactor/includes.js

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

3+
// function includes(list, target) {
4+
// for (let index = 0; index < list.length; index++) {
5+
// const element = list[index];
6+
// if (element === target) {
7+
// return true;
8+
// }
9+
// }
10+
// return false;
11+
// }
312
function includes(list, target) {
4-
for (let index = 0; index < list.length; index++) {
5-
const element = list[index];
13+
for (let element of list) {
614
if (element === target) {
15+
console.log("true");
716
return true;
817
}
918
}
19+
console.log("false");
1020
return false;
1121
}
22+
const new_list = [1, 2, 3, 4, 5, 7];
23+
const tar = 5;
24+
includes(new_list, tar);
25+
// console.log(includes([1, 2, 3]), 3);
1226

1327
module.exports = includes;

0 commit comments

Comments
 (0)