-
Notifications
You must be signed in to change notification settings - Fork 0
/
find.js
29 lines (22 loc) · 797 Bytes
/
find.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function myFind (list, callback) {
if (!callback && !list) {
return "ERROR theres no callback function and no array so we couldnt find first matched element";
} else if (callback === undefined) {
return "ERROR no callback function so we couldnt find first matched element";
}
else if(list === undefined){
return "ERROR no array parameter"
}else if (!Array.isArray(list)) {
return "ERROR native find function dont accept object";
}
for (let item of list) {
if (callback(item)) {
return item;
}
}
return undefined;
}
let array =[1,2,3,4,5]
let found=myFind(array,element => element > 1)
console.log(found);
module.exports= myFind;