Code review result
This commit is contained in:
parent
e4f9de10ff
commit
4d9ac979e9
|
|
@ -29,23 +29,22 @@ const pizzas = [
|
|||
const pizzaInfo = {
|
||||
|
||||
getPizzaInfoByPizzaName: function (pizza) {
|
||||
if (pizza === undefined) {
|
||||
return "В ассортимент пиццерии \"ДоРеМи\" входят пиццы " + pizzas.map((pizza) => "\"" + pizza.name + "\"").reduce((prev, next) => prev + ", " + next) + ". Могу рассказать состав каждой пиццерии."
|
||||
} else {
|
||||
return "В пиццу \"" + pizza.name + "\" входят " + pizza.ingredients.map((pizza) => pizza.toLowerCase()).reduce((prev, next) => prev + ", " + next) + "."
|
||||
const wrapName = name => `"${name}"`
|
||||
|
||||
if (!pizza) {
|
||||
const pizzaNames = pizzas.map(pizza => wrapName(pizza.name)).join(", ")
|
||||
return `В ассортимент пиццерии "ДоРеМи" входят пиццы ${pizzaNames}. Могу рассказать состав каждой пиццерии.`
|
||||
}
|
||||
|
||||
const ingredients = pizza.ingredients.map(ingredient => ingredient.toLowerCase()).join(", ")
|
||||
return `В пиццу ${wrapName(pizza.name)} входят ${ingredients}.`
|
||||
},
|
||||
|
||||
getPizzaInfoByUserCommand: function (command) {
|
||||
command = command.toLowerCase();
|
||||
const pizza = pizzas.find((pizza) => {
|
||||
let contains = false;
|
||||
pizza.base_name.forEach((base) => {
|
||||
contains = contains || command.indexOf(base) !== -1
|
||||
});
|
||||
return contains
|
||||
}
|
||||
);
|
||||
const pizza = pizzas.find(pizza => (
|
||||
pizza.base_name.some(base => (command.indexOf(base) !== -1))
|
||||
))
|
||||
|
||||
return this.getPizzaInfoByPizzaName(pizza)
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
var express = require('express');
|
||||
var pizzaInfo = require('../pizza/pizza_info.js');
|
||||
var router = express.Router();
|
||||
const express = require('express');
|
||||
const pizzaInfo = require('../pizza/pizza_info.js');
|
||||
const router = express.Router();
|
||||
|
||||
/* GET home page. */
|
||||
router.get('/', function (req, res, next) {
|
||||
const pizzaName = req.query['pizza'];
|
||||
if (pizzaName !== undefined) {
|
||||
if (pizzaName != null) {
|
||||
res.send(pizzaInfo.getPizzaInfoByUserCommand(pizzaName))
|
||||
} else {
|
||||
res.send("Делаем музыкальную пиццу")
|
||||
|
|
|
|||
Loading…
Reference in New Issue