$ mocha *.test.js
peopleQuery
{ Male: [ 'Kristoforo', 'Clark' ],
Female: [ 'Ruthanne', 'Buffy' ] }
✓ query
1 passing (10ms)
Created
January 28, 2019 16:54
-
-
Save unicornist/4b67d8e9f7095f10da47e7db5e1e22b3 to your computer and use it in GitHub Desktop.
Hotjar Application Problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = (people) => people.reduce((result, person) => { | |
if (person.age>30 && person.age<40) | |
result[person.gender].push(person.name) | |
return result; | |
}, {"Male": [], "Female": []}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { expect } = require("chai"); | |
const peopleQuery = require("./people-query"); | |
// Sample data from https://www.mockaroo.com/ | |
const testPeople = [ | |
{ "name": "Betsey", "gender": "Female", "age": 29 }, | |
{ "name": "Kristoforo", "gender": "Male", "age": 31 }, | |
{ "name": "Ruthanne", "gender": "Female", "age": 38 }, | |
{ "name": "Crichton", "gender": "Male", "age": 25 }, | |
{ "name": "Rafaello", "gender": "Male", "age": 41 }, | |
{ "name": "Clark", "gender": "Male", "age": 39 }, | |
{ "name": "Meade", "gender": "Male", "age": 26 }, | |
{ "name": "Anastasia", "gender": "Female", "age": 50 }, | |
{ "name": "Buffy", "gender": "Female", "age": 35 }, | |
{ "name": "Korrie", "gender": "Female", "age": 26 } | |
]; | |
describe("peopleQuery", () => { | |
it("query", () => { | |
const queryResult = peopleQuery(testPeople); | |
console.log(queryResult) | |
expect(queryResult).to.have.property('Male').with.lengthOf(2); | |
expect(queryResult).to.have.property('Female').with.lengthOf(2); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment