Skip to content

Instantly share code, notes, and snippets.

@unicornist
Created January 28, 2019 16:54
Show Gist options
  • Save unicornist/4b67d8e9f7095f10da47e7db5e1e22b3 to your computer and use it in GitHub Desktop.
Save unicornist/4b67d8e9f7095f10da47e7db5e1e22b3 to your computer and use it in GitHub Desktop.
Hotjar Application Problem
module.exports = (people) => people.reduce((result, person) => {
if (person.age>30 && person.age<40)
result[person.gender].push(person.name)
return result;
}, {"Male": [], "Female": []});
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);
});
});
$ mocha *.test.js


  peopleQuery
{ Male: [ 'Kristoforo', 'Clark' ],
  Female: [ 'Ruthanne', 'Buffy' ] }
    ✓ query


  1 passing (10ms)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment