1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
| require("../../support"); var _ = require("ramda"); var accounting = require("accounting");
var CARS = [ { name: "Ferrari FF", horsepower: 660, dollar_value: 700000, in_stock: true }, { name: "Spyker C12 Zagato", horsepower: 650, dollar_value: 648000, in_stock: false, }, { name: "Jaguar XKR-S", horsepower: 550, dollar_value: 132000, in_stock: false, }, { name: "Audi R8", horsepower: 525, dollar_value: 114200, in_stock: false }, { name: "Aston Martin One-77", horsepower: 750, dollar_value: 1850000, in_stock: true, }, { name: "Pagani Huayra", horsepower: 700, dollar_value: 1300000, in_stock: false, }, ];
var _isLastInStock = function (cars) { var last_car = _.last(cars); return _.prop("in_stock", last_car); };
const isLastInStock = _.compose(_.prop("in_stock"), _.last);
var nameOfFirstCar = _.compose(_.prop("name"), _.head);
var _average = function (xs) { return reduce(add, 0, xs) / xs.length; };
var _averageDollarValue = function (cars) { var dollar_values = map(function (c) { return c.dollar_value; }, cars); return _average(dollar_values); };
const averageDollarValue = _.compose(_average, map(_.prop("dollar_value")));
var _underscore = replace(/\W+/g, "_");
var sanitizeNames = _.compose( _.map(_underscore), _.map(_.toLower), _.map(_.prop("name")) );
var sanitizeNames2 = _.map(_.compose(_.toLower, _underscore, _.prop("name")));
var _availablePrices = function (cars) { var available_cars = _.filter(_.prop("in_stock"), cars); return available_cars .map(function (x) { return accounting.formatMoney(x.dollar_value); }) .join(", "); };
var availablePrices = _.compose( _.join(", "), _.map(_.compose(accounting.formatMoney, _.prop("dollar_value"))), _.filter(_.prop("in_stock")) );
var _fastestCar = function (cars) { var sorted = _.sortBy(function (car) { return car.horsepower; }, cars); var fastest = _.last(sorted); return fastest.name + " is the fastest"; };
var fastestCar = _.compose( _.flip(_.concat)(" is the fastest"), _.prop("name"), _.last, _.sortBy(_.prop("horsepower")) );
module.exports = { CARS: CARS, isLastInStock: isLastInStock, nameOfFirstCar: nameOfFirstCar, fastestCar: fastestCar, averageDollarValue: averageDollarValue, availablePrices: availablePrices, sanitizeNames: sanitizeNames, };
|