-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworksheet_assessmentMissed.js
More file actions
67 lines (58 loc) · 3.15 KB
/
worksheet_assessmentMissed.js
File metadata and controls
67 lines (58 loc) · 3.15 KB
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
/**
* CHALLENGE 1: Get Students
* You are working for a music school and are tasked with creating a way to search
* through a student list. Define a function `getStudents` that takes two arguments,
* an array `students` and a callback function `searchCriterion`.
* The callback function will be a test that returns a boolean based on the input.
* `getStudents` should filter the input `students` array based on the criterion
* provided by the `searchCriterion` callback function. `getStudents` should return
* a new array containing only the students' names.
*
* Ok. First telling us to use filter.
* function with two parameters (students, searchCriterion)
* searchCriterion will be a boolean based on input; returning only names;
*/
let getStudents = students.filter()
// UNCOMMENT THESE LINES TO CHECK YOUR WORK
// const students = [
// { name: 'Wyatt', score: 90, instrument: 'violin' },
// { name: 'Bella', score: 60, instrument: 'cello' },
// { name: 'Patrick', score: 50, instrument: 'tuba' },
// { name: 'Briana', score: 85, instrument: 'clarinet' },
// { name: 'Jane', score: 40, instrument: 'violin' },
// { name: 'Maria', score: 70, instrument: 'cello' },
// { name: 'Emilio', score: 75, instrument: 'violin' },
// { name: 'Vijeta', score: 45, instrument: 'flute' },
// ];
// const isAbove50 = (n) => n.score > 50;
// const playsViolin = (n) => n.instrument === 'violin';
// console.log(getStudents(students, isAbove50)); // should log: ['Wyatt', 'Bella', 'Briana', 'Maria', 'Emilio']
// console.log(getStudents(students, playsViolin)); // should log: ['Wyatt', 'Jane', 'Emilio']
/**
* CHALLENGE 2: Process Orders
* You are developing a system to process online orders. Define a function
* `processOrders` that takes two arguments, an array `orders` and a callback
* function `processOrder`. The callback function will return a processed
* order object based on the input. `processOrders` should apply the `processOrder`
* callback function to each order in the orders array and return a new array
* containing the processed orders.
*
*/
//ok, this looks like a map funciton to me. I am not very comfortable with Map, and everyone uses arrow functions with it
// but i know it takes in
// a function that is applied to each element and returns a new array
//function processOrders ([], processOrder) {
//}
//let processOrders = orders.map((e) => {return processOrder();})
// UNCOMMENT THESE LINES TO CHECK YOUR WORK
// const orders = [
// { id: 1, item: 'Laptop', quantity: 2 },
// { id: 2, item: 'Phone', quantity: 1 },
// { id: 3, item: 'Tablet', quantity: 3 },
// ];
// const addShipping = (o) => ({ ...o, shipping: 10 });
// const applyDiscount = (o) => ({ ...o, total: o.quantity * 100 - 20 });
// console.log(processOrders(orders, addShipping));
// // should log: [{ id: 1, item: 'Laptop', quantity: 2, shipping: 10 }, { id: 2, item: 'Phone', quantity: 1, shipping: 10 }, { id: 3, item: 'Tablet', quantity: 3, shipping: 10 }]
// console.log(processOrders(orders, applyDiscount));
// // should log: [{ id: 1, item: 'Laptop', quantity: 2, total: 180 }, { id: 2, item: 'Phone', quantity: 1, total: 80 }, { id: 3, item: 'Tablet', quantity: 3, total: 280 }]