forked from kipchirchiralb/JavaScript-C2-23
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter.js
More file actions
31 lines (27 loc) · 726 Bytes
/
Copy pathfilter.js
File metadata and controls
31 lines (27 loc) · 726 Bytes
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
const words = [
"spray",
"limit",
"elite",
"exuberant",
"destruction",
"present",
];
function callbackFnc(word) {
return word.length > 6;
}
const longWordsOver6Chars = words.filter(callbackFnc);
// console.log(longWordsOver6Chars);
// console.log(words);
// Given an array of numbers, write a function that filters out the even numbers and returns a new array containing only the odd numbers
let numbers = [23, 4, 54, 75, 4, 55, 6, 7, 2];
let oddNumbers = numbers.filter(function (elem) {
return elem % 2 == 1;
});
let newOddNumbers = [];
for (let i = 0; i < numbers.length; i++) {
if (numbers[i] % 2 == 1) {
newOddNumbers.push(numbers[i]);
}
}
console.log(oddNumbers);
console.log(newOddNumbers);