-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter_geese.js
37 lines (28 loc) · 1.43 KB
/
filter_geese.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
// Write a function that takes a list of strings as an argument and returns a filtered list
// containing the same elements but with the 'geese' removed.
// The geese are any strings in the following array, which is pre-populated in your solution:
// ["African", "Roman Tufted", "Toulouse", "Pilgrim", "Steinbacher"]
// For example, if this array were passed as an argument:
// ["Mallard", "Hook Bill", "African", "Crested", "Pilgrim", "Toulouse", "Blue Swedish"]
// Your function would return the following array:
// ["Mallard", "Hook Bill", "Crested", "Blue Swedish"]
// The elements in the returned array should be in the same order as
// in the initial array passed to your function, albeit with the 'geese' removed.
// Note that all of the strings will be in the same case as those provided, and
// some elements may be repeated.
function gooseFilter (birds) {
let geese = ["African", "Roman Tufted", "Toulouse", "Pilgrim", "Steinbacher"];
// return an array containing all of the strings in the input array except those that match strings in geese
return birds.filter(b => !geese.includes(b))
};
// option 2
function gooseFilter2 (birds) {
let geese = ["African", "Roman Tufted", "Toulouse", "Pilgrim", "Steinbacher"];
let newArray = [];
for (var i = 0; i < birds.length; i++) {
if (!geese.includes(birds[i])) {
newArray.push(birds[i]);
}
}
return newArray;
};