File tree Expand file tree Collapse file tree 1 file changed +30
-3
lines changed
exercises/concept/pizza-order Expand file tree Collapse file tree 1 file changed +30
-3
lines changed Original file line number Diff line number Diff line change 11/// <reference path="./global.d.ts" />
2+
3+ import { forEach } from "core-js/core/array"
4+
25//
36// @ts -check
47
58/**
69 * Determine the price of the pizza given the pizza and optional extras
710 *
8- * @param {Pizza } pizza name of the pizza to be made
11+ * @param {Pizz a } pizza name of the pizza to be made
912 * @param {Extra[] } extras list of extras
1013 *
1114 * @returns {number } the price of the pizza
1215 */
1316export function pizzaPrice ( pizza , ...extras ) {
14- throw new Error ( 'Please implement the pizzaPrice function' ) ;
17+ const PizzaPrice = {
18+ Margherita : 7 ,
19+ Caprese : 9 ,
20+ Formaggio : 10 ,
21+ }
22+ const extrasPrice = {
23+ ExtraSauce : 1 ,
24+ ExtraToppings : 2 ,
25+ }
26+ let price = PizzaPrice [ pizza ] || 0
27+ for ( const extra of extras ) {
28+ price += extrasPrice [ extra ] || 0
29+ }
30+ return price
1531}
1632
1733/**
@@ -24,5 +40,16 @@ export function pizzaPrice(pizza, ...extras) {
2440 * @returns {number } the price of the total order
2541 */
2642export function orderPrice ( pizzaOrders ) {
27- throw new Error ( 'Please implement the orderPrice function' ) ;
43+ if ( pizzaOrders . length === 0 ) {
44+ return 0 ;
45+ }
46+
47+ let totalPrice = 0
48+
49+ pizzaOrders . forEach ( order => {
50+ totalPrice += pizzaPrice ( order . pizza , ...order . extras )
51+ } )
52+
53+ return totalPrice
54+ // throw new Error('Please implement the orderPrice function');
2855}
You can’t perform that action at this time.
0 commit comments