-
Notifications
You must be signed in to change notification settings - Fork 908
/
index.js
159 lines (148 loc) · 4.33 KB
/
index.js
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/**
* [Exercise 1] trimProperties copies an object trimming its properties
* @param {object} obj - an object with properties that are strings
* @returns {object} - a copy of the object with strings trimmed
*
* EXAMPLE
* trimProperties({ name: ' jane ' }) // returns a new object { name: 'jane' }
*/
function trimProperties(obj) {
// ✨ implement
}
/**
* [Exercise 2] trimPropertiesMutation trims in place the properties of an object
* @param {object} obj - an object with properties that are strings
* @returns {object} - the same object with strings trimmed
*
* EXAMPLE
* trimPropertiesMutation({ name: ' jane ' }) // returns the object mutated in place { name: 'jane' }
*/
function trimPropertiesMutation(obj) {
// ✨ implement
}
/**
* [Exercise 3] findLargestInteger finds the largest integer in an array of objects { integer: 1 }
* @param {object[]} integers - an array of objects
* @returns {number} - the largest integer
*
* EXAMPLE
* findLargestInteger([{ integer: 1 }, { integer: 3 }, { integer: 2 }]) // returns 3
*/
function findLargestInteger(integers) {
// ✨ implement
}
class Counter {
/**
* [Exercise 4A] Counter creates a counter
* @param {number} initialNumber - the initial state of the count
*/
constructor(initialNumber) {
// ✨ initialize whatever properties are needed
}
/**
* [Exercise 4B] Counter.prototype.countDown counts down to zero
* @returns {number} - the next count, does not go below zero
*
* EXAMPLE
* const counter = new Counter(3)
* counter.countDown() // returns 3
* counter.countDown() // returns 2
* counter.countDown() // returns 1
* counter.countDown() // returns 0
* counter.countDown() // returns 0
*/
countDown() {
// ✨ implement
}
}
class Seasons {
/**
* [Exercise 5A] Seasons creates a seasons object
*/
constructor() {
// ✨ initialize whatever properties are needed
}
/**
* [Exercise 5B] Seasons.prototype.next returns the next season
* @returns {string} - the next season starting with "summer"
*
* EXAMPLE
* const seasons = new Seasons()
* seasons.next() // returns "summer"
* seasons.next() // returns "fall"
* seasons.next() // returns "winter"
* seasons.next() // returns "spring"
* seasons.next() // returns "summer"
*/
next() {
// ✨ implement
}
}
class Car {
/**
* [Exercise 6A] Car creates a car object
* @param {string} name - the name of the car
* @param {number} tankSize - capacity of the gas tank in gallons
* @param {number} mpg - miles the car can drive per gallon of gas
*/
constructor(name, tankSize, mpg) {
this.odometer = 0 // car initilizes with zero miles
this.tank = tankSize // car initiazes full of gas
// ✨ initialize whatever other properties are needed
}
/**
* [Exercise 6B] Car.prototype.drive adds miles to the odometer and consumes fuel according to mpg
* @param {string} distance - the distance we want the car to drive
* @returns {number} - the updated odometer value
*
* EXAMPLE
* const focus = new Car('focus', 20, 30)
* focus.drive(100) // returns 100
* focus.drive(100) // returns 200
* focus.drive(100) // returns 300
* focus.drive(200) // returns 500
* focus.drive(200) // returns 600 (ran out of gas after 100 miles)
*/
drive(distance) {
// ✨ implement
}
/**
* [Exercise 6C] Adds gallons to the tank
* @param {number} gallons - the gallons of fuel we want to put in the tank
* @returns {number} - the miles that can be driven after refueling
*
* EXAMPLE
* const focus = new Car('focus', 20, 30)
* focus.drive(600) // returns 600
* focus.drive(1) // returns 600 (no distance driven as tank is empty)
* focus.refuel(99) // returns 600 (tank only holds 20)
*/
refuel(gallons) {
// ✨ implement
}
}
/**
* [Exercise 7] Asynchronously resolves whether a number is even
* @param {number} number - the number to test for evenness
* @returns {promise} - resolves true if number even, false otherwise
*
* EXAMPLE
* isEvenNumberAsync(2).then(result => {
* // result is true
* })
* isEvenNumberAsync(3).then(result => {
* // result is false
* })
*/
function isEvenNumberAsync(number) {
// ✨ implement
}
module.exports = {
trimProperties,
trimPropertiesMutation,
findLargestInteger,
isEvenNumberAsync,
Counter,
Seasons,
Car,
}