-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistFiltering.js
81 lines (60 loc) · 2.03 KB
/
listFiltering.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// https://www.codewars.com/kata/53dbd5315a3c69eed20002dd/train/javascript
// In this kata you will create a function that takes a list of non-negative integers and strings and returns a new list with the strings filtered out.
// Example
// filter_list([1,2,'a','b']) == [1,2]
// filter_list([1,'a','b',0,15]) == [1,0,15]
// filter_list([1,2,'aasf','1','123',123]) == [1,2,123]
function filter_list(l) {
// Return a new array with the strings filtered out
const result = l.filter(function(item) {
return typeof item === 'number';
});
// compare type to be a number
return result;
}
//filter is looking for the typeof = number
//running an array through the filter
//l is our parameter
//ex list [4, 6, 8, 'y' 'b'] = [4, 6, 8]
/*const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
const result = words.filter(word => word.length > 6);
console.log(result);
// expected output: Array ["exuberant", "destruction", "present"]*/
////////Alt:
function filter_list(l) {
return l.filter(e => Number.isInteger(e));
}
function filter_list(l) {
return l.filter(e => Number.isInteger(e));
}
function filter_list(l) {
return l.filter(e => Number.isInteger(e));
}
function filter_list(l) {
return l.filter(e => Number.isInteger(e));
}
function filter_list(l) {
return l.filter(e => Number.isInteger(e));
}
function filter_list(l) {
return l.filter(e => Number.isInteger(e));
}
function filter_list(l) {
return l.filter(e => Number.isInteger(e));
}
/////Alt:
function filter_list(l) {
return l.filter((el) => typeof(el) == 'number')
}
function filter_list(l) {
return l.filter((el) => typeof(el) == Number) //why doesn't this work?
}
function filter_list(l) {
return l.filter((el) => typeof(el) == 'number')
}
function filter_list(l) {
return l.filter((el) => typeof(el) == 'number')
}
function filter_list(l) {
return l.filter((el) => typeof(el) == 'number')
}