Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cea9afc

Browse files
committed
Removed the TODO comments.
1 parent 0ea7111 commit cea9afc

File tree

2 files changed

+2
-52
lines changed

2 files changed

+2
-52
lines changed

Week2/prep-exercises/1-traffic-light/traffic-light.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,10 @@
66
*/
77

88
function getCurrentState(trafficLight) {
9-
// TODO
10-
// Should return the current state (i.e. colour) of the `trafficLight`
11-
// object passed as a parameter.
12-
139
return trafficLight.possibleStates[trafficLight.stateIndex];
1410
}
1511

1612
function getNextStateIndex(trafficLight) {
17-
// TODO
18-
// Return the index of the next state of the `trafficLight` such that:
19-
// - if the color is green, it will turn to orange
20-
// - if the color is orange, it will turn to red
21-
// - if the color is red, it will turn to green
22-
2313
return (trafficLight.stateIndex + 1) % trafficLight.possibleStates.length;
2414
}
2515

Week2/prep-exercises/2-experiments/index.js

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,13 @@
22

33
function runExperiment(sampleSize) {
44
const valueCounts = [0, 0, 0, 0, 0, 0];
5-
6-
7-
8-
// TODO
9-
// Write a for loop that iterates `sampleSize` times (sampleSize is a number).
10-
// In each loop iteration:
11-
//
12-
// 1. Generate a random integer between 1 and 6 (as if throwing a six-sided die).
13-
// 2. Add `1` to the element of the `valueCount` that corresponds to the random
14-
// value from the previous step. Use the first element of `valueCounts`
15-
// for keeping a count how many times the value 1 is thrown, the second
16-
// element for value 2, etc.
17-
185
for(let ii = 0; ii < sampleSize; ii++){
196
let randomNumber = Math.floor(Math.random() * 6) + 1;
20-
valueCounts[(randomNumber-1)]++;
7+
valueCounts[(randomNumber - 1)]++;
218
}
229

23-
// valueCounts.forEach((value, index) => {
24-
// console.log(`The value ${index+1} appeard ${value}`);
25-
// });
26-
2710
const results = [];
28-
29-
// TODO
30-
// Write a for..of loop for the `valueCounts` array created in the previous
31-
// loop. In each loop iteration:
32-
// 1. For each possible value of the die (1-6), compute the percentage of how
33-
// many times that value was thrown. Remember that the first value of
34-
// `valueCounts` represent the die value of 1, etc.
35-
// 2. Convert the computed percentage to a number string with a precision of
36-
// two decimals, e.g. '14.60'.
37-
// 3. Then push that string onto the `results` array.
38-
39-
let sum = valueCounts.reduce((accumlator, value) => accumlator + value, 0);
11+
let sum = valueCounts.reduce((accumulator, value) => accumulator + value, 0);
4012

4113
for(let value of valueCounts){
4214
let percentage = (value / sum) * 100;
@@ -48,18 +20,6 @@ function runExperiment(sampleSize) {
4820

4921
function main() {
5022
const sampleSizes = [100, 1000, 1000000];
51-
//const sampleSizes = [100];
52-
// TODO
53-
// Write a for..of loop that calls the `runExperiment()` function for each
54-
// value of the `sampleSizes` array.
55-
// Log the results of each experiment as well as the experiment size to the
56-
// console.
57-
// The expected output could look like this:
58-
//
59-
// [ '26.00', '17.00', '10.00', '19.00', '16.00', '12.00' ] 100
60-
// [ '14.60', '17.10', '19.30', '15.50', '16.70', '16.80' ] 1000
61-
// [ '16.71', '16.68', '16.69', '16.66', '16.67', '16.59' ] 1000000
62-
6323
for(let sample of sampleSizes){
6424
const results = runExperiment(sample);
6525
const formattedResults = `[ ${ results.map(result => `'${result}'`).join(', ') }] ${sample}`;

0 commit comments

Comments
 (0)