Repository navigation
Expand file tree
/
Copy pathfunctions.js
More file actions
99 lines (92 loc) · 4.01 KB
/
Copy pathfunctions.js
File metadata and controls
99 lines (92 loc) · 4.01 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
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
// Callbacks
// Step 1: Create a higher-order function that will accept 3 parameters. The first two can take any argument. The last is your callback. This function should return your callback that passed the first two parameters as its argument.
function consume(x, y, cb) {
return cb(x, y);
}
/* Step 2: Create several functions that you will callback with the previous higher order function.
The first will return the sum of two numbers.
The second will return the product of two numbers.
The third will return the modulus of the two numbers.
The fourth will return the quotient of the two numbers.
The fifth will return the square root of the two numbers.
The sixth will accept a first and last name and return 'Hey, firstName lastName, youre a wicked cool dev'.
The seventh will return whether the firstString is included the secondString.
The eigth will return whether the firstNumber is greater than the secondNumber.
The ninth will return whether the firstNumber is less than the secondNumber.
The tenth will return whether the firstNumber is greater than or equal to the secondNumber.
The eleventh will return whether the firstNumber is less than or equal to the secondNumber.
The twelvth will return whether the firstNumber is equivalent to the secondNumber.
The thirteenth will return a string 'Hey the number is firstNumber' if firstNumber is greater than the secondNumber. If it isn't, return a string 'Hey the number is secondNumber'
*/
function add(num1, num2) {
return num1 + num2;
}
// The second will return the product of two numbers.
function multiply(num1, num2) {
return num1 * num2;
}
// The third will return the modulus of the two numbers.
function remainder(num1, num2) {
return num1 % num2;
}
// The fourth will return the quotient of the two numbers.
function divide(num1, num2) {
return num1/num2;
}
// The fifth will return the square root of the two numbers.
function square(num1, num2) {
let var1 = Math.sqrt(num1);
let var2 = Math.sqrt(num2);
// return var1 + " " + var2;
return `${var1} ${var2}`;
}
// The sixth will accept a first and last name and return 'Hey, firstName lastName, youre a wicked cool dev'.
function stringReturn(firstName, lastName) {
return `Hey, ${firstName} ${lastName}, youre a wicked cool dev`;
}
// The seventh will return whether the firstString is included the secondString.
function stringIncludes(firstString, secondString) {
return secondString.includes(firstString);
}
// The eigth will return whether the firstNumber is greater than the secondNumber.
function numCompare1(x, y) {
return x > y;
}
// The ninth will return whether the firstNumber is less than the secondNumber.
function numCompare2(x,y) {
return x < y;
}
// The tenth will return whether the firstNumber is greater than or equal to the secondNumber.
function numCompare3(x,y) {
return x >= y;
}
// The eleventh will return whether the firstNumber is less than or equal to the secondNumber.
function numCompare4(x,y) {
return x <= y;
}
// The twelvth will return whether the firstNumber is equivalent to the secondNumber.
function numCompare5(x,y) {
return x === y;
}
// The thirteenth will return a string 'Hey the number is firstNumber' if firstNumber is greater than the secondNumber. If it isn't, return a string 'Hey the number is secondNumber'
function numCompare6(x, y) {
if(x > y) {
return `Hey the number is ${x}`;
} else {
return `Hey the number is ${y}`;
}
}
// Step 3: Check your work using console.log and invoke your higher order function.
console.log(consume(1, 2, add), "This is to add");
console.log(consume(2, 2, multiply));
console.log(consume(2, 3, remainder));
console.log(consume(2, 4, divide));
console.log(consume(4, 16, square));
console.log(consume('bob', 'bobbington', stringReturn));
console.log(consume('bob', 'bob went to the store', stringIncludes));
console.log(consume(2,5, numCompare1));
console.log(consume(2,5, numCompare2));
console.log(consume(2,5, numCompare3));
console.log(consume(2,5, numCompare4));
console.log(consume(2,5, numCompare5));
console.log(consume(2,5, numCompare6));