'use strict';

var express = require('express');
var router = express.Router();

var nameManager = require('../name_manager');

/* POST the n most popular names. */
router.post('/popular', function(req, res, next) {
  res.setHeader('Content-Type', 'application/json');
  let names = nameManager.getMostPopular(req.body.range, req.body.number, n => n.startsWith(req.body.startsWith.toLowerCase()));
  res.send(names);
});

module.exports = router;

@@ -121,16 +121,333 @@
 ger');%0A%0A
+var createPredicate = function(gender, startsWith) %7B%0A  gender = gender.toLowerCase();%0A  startsWith = startsWith.toLowerCase();%0A  return (n) =%3E (startsWith == undefined ? true : n.startsWith(startsWith) && %0A    ((gender == undefined %7C%7C gender === 'both') ? true : (gender === 'male' ? n.isMale() : n.isFemale())))%0A%7D;%0A%0A
 /* POST 
@@ -657,59 +657,60 @@
 er, 
-n =%3E n.startsWith(req.body.startsWith.toLowerCase()
+createPredicate(req.body.gender, req.body.startsWith
 ));%0A

add predicate creation to controller