1const array = [ { username: "john", team: "red", score: 5, items: ["ball", "book", "pen"]
2 },
3 {
4 username: "becky",
5 team: "blue",
6 score: 10,
7 items: ["tape", "backpack", "pen"]
8 },
9 {
10 username: "susy",
11 team: "red",
12 score: 55,
13 items: ["ball", "eraser", "pen"]
14 },
15 {
16 username: "tyson",
17 team: "green",
18 score: 1,
19 items: ["book", "pen"]
20 },
21
22];
23//FILTER MEMBERS IN TEAM "RED"
24const filterArray=array.filter(word=>word.team==="red")
1var words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
2
3const result = words.filter(word => word.length > 6);
4
5console.log(result);
1function objectFilter = (obj, predicate) =>
2 Object.keys(obj)
3 .filter( key => predicate(obj[key]) )
4 .reduce( (res, key) => (res[key] = obj[key], res), {} );
5
6// Example use:
7var scores = {
8 John: 2, Sarah: 3, Janet: 1
9};
10
11var filtered = objectFilter(scores, num => num > 1);
12console.log(filtered);
1const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
2
3const result = words.filter(word => word.length > 6);
4
5console.log(result);
6// expected output: Array ["exuberant", "destruction", "present"]
1function filter(array, test) {
2 let passed = [];
3 for (let element of array) {
4 if (test(element)) {
5 passed.push(element);
6 }
7 }
8 return passed;
9}
10
11console.log(filter(SCRIPTS, script => script.living));
12// → [{name: "Adlam", …}, …]