Update: please note that I have since switched to using a set of bash scripts instead of poluting the Git repository with git svn.
Author: Kaspars Dambis
kaspars.net / @konstruktors
Update: please note that I have since switched to using a set of bash scripts instead of poluting the Git repository with git svn.
Author: Kaspars Dambis
kaspars.net / @konstruktors
| const { expect } = require("chai") | |
| function flatten(array) { | |
| return array.reduce((acc, val) => acc.concat(Array.isArray(val) ? flatten(val) : val), []) | |
| } | |
| describe("#flatten", () => { | |
| it("should return flattened array", () => { | |
| const input = [[1, 2, [3]], 4] | |
| expect(flatten(input)).to.deep.equal([1, 2, 3, 4]) |
| function orderByRank(array) { | |
| var arrayCopy = array.slice(); // if we don't want to modify org array | |
| arrayCopy.sort(function(a, b) { | |
| return a.ranking - b.ranking; | |
| }); | |
| return arrayCopy; | |
| } |
| function objectsByRanking(data) { | |
| return data.sort(function(a, b) { return a.ranking - b.ranking; }) | |
| } | |
| function averageRanking(data) { | |
| return data.reduce( | |
| function(prev, curr) { return { ranking: prev.ranking + curr.ranking }; }, { ranking: 0 } | |
| ).ranking / data.length; | |
| } |
| function discriminator(data) { | |
| if (!data) { | |
| return null; | |
| } | |
| return data.filter(function(item) { | |
| return item.age >= 30 && item.age <= 40; | |
| }); | |
| } |