Skip to content

Commit

Permalink
Update Hero Search API from exact match to contains
Browse files Browse the repository at this point in the history
  • Loading branch information
smmorneau committed Oct 30, 2016
1 parent 41d8bc1 commit 58d77c6
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ var heroes = [
];

app.get('/app/heroes', function(req, res) {
const name = req.query.name;
var name = req.query.name;
if (name) {
var result = _.find(heroes, function(hero) { return hero.name.toLowerCase() === name.toLowerCase() });
res.json(result ? [result] : []);
name = name.toLowerCase();
var results = _.filter(heroes, function(hero) {
return _.includes(hero.name.toLowerCase(), name);
});
res.json(results);
} else {
res.json(heroes);
}
Expand Down

0 comments on commit 58d77c6

Please sign in to comment.