From 58d77c6de85c921270b2e35030c482007ced1b7f Mon Sep 17 00:00:00 2001 From: Steely Morneau Date: Sat, 29 Oct 2016 21:52:57 -0700 Subject: [PATCH] Update Hero Search API from exact match to contains --- server.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/server.js b/server.js index b7e62f3..4235f19 100644 --- a/server.js +++ b/server.js @@ -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); }