Skip to content

Commit

Permalink
Done exercise-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Nguyen committed Mar 2, 2022
1 parent 9564df4 commit 9d1076b
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions 8-using-inheritance/exercises/exercise-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"use strict";

class FunctionalSet extends Set {
filter(predicate) {
return new FunctionalSet([...this].filter(predicate));
}
map(mapper) {
return new FunctionalSet([...this].map(mapper));
}
reduce(accumulator, identity) {
return [...this].reduce(accumulator, identity);
}
}

const set = new FunctionalSet(["Jack", "Jill", "Tom", "Jerry"]);

const jSet = set.filter((name) => name.startsWith("J"));
const allCaps = set.map((name) => name.toUpperCase());

const totalLengthOfJWords = set
.filter((name) => name.startsWith("J"))
.reduce((total, word) => total + word.length, 0);

console.log(jSet);
console.log(allCaps);
console.log(totalLengthOfJWords);

0 comments on commit 9d1076b

Please sign in to comment.