/* Return the owner and repo name of the most starred project with more than 100 contributors, for each language The declarative implementation can be solved using the map, filter, reduce and groupBy from the underscore library In order to chain your higher order function calls (as you would using, say, jQuery), use the _.chain() function. */ const _ = require('underscore'); const repos = [ { owner: 'Alice', name: 'Swish', stars: 611, language: 'C++', contributors: 170 }, { owner: 'Bob', name: 'Thermos', stars: 218, language: 'Python', contributors: 26 }, { owner: 'Charlie', name: 'Glint', stars: 335, language: 'C#', contributors: 53 }, { owner: 'Dylan', name: 'B2', stars: 13856, language: 'JavaScript', contributors: 64 }, { owner: 'Evelyn', name: 'Logang', stars: 5834, language: 'Go', contributors: 39 }, { owner: 'Francis', name: 'Blocker', stars: 10436, language: 'Go', contributors: 107 }, { owner: 'Geri', name: 'Curvature', stars: 8029, language: 'JavaScript', contributors: 387 }, { owner: 'Harry', name: 'Proact', stars: 7431, language: 'JavaScript', contributors: 242 }, { owner: 'Iona', name: 'Stereo', stars: 9848, language: 'C#', contributors: 153 }, { owner: 'Jamie', name: 'Blueis', stars: 4360, language: 'C', contributors: 12 }, { owner: 'Kerry', name: 'RightPad', stars: 5, language: 'JavaScript', contributors: 1 } ]; // Return the owner and repo name of the most starred project with more than 100 contributors, for each language const declarative = function(repos) { return null; }; const imperative = function(repos) { let mostStarredRepos = {}; for (repo of repos) { if (repo.contributors <= 100) { continue; } if (!(repo.language in mostStarredRepos) || repo.stars > mostStarredRepos[repo.language].stars) { mostStarredRepos[repo.language] = repo; } } let ownerAndRepos = []; for (repo in mostStarredRepos) { ownerAndRepos.push({ owner: mostStarredRepos[repo].owner, name: mostStarredRepos[repo].name }); } return ownerAndRepos; }; declarative(repos); imperative(repos);