Ok, I’m almost halfway through The Isles of the Gods, and I know a particular event is going to happen cause they foreshadowed the heck out of it. So now I’m just eagerly waiting for this to happen. It must be what the whole second half of the book will be about. I like it. It has some Pirates of the Carribean vibes. I have not watched Pirates of the Carribean. But I have watched scenes and been to Disneyland.
The movie last night was a double feature. I particularly enjoyed how the film wrapped the series in a nice little bow. The first movie, Rascal does not dream of a sister venturing out, was fun. The second one, Rascal does not dream of a knapsack kid, was quite emotional but still enjoyable. I don’t know if they will continue the anime series or make more movies. There are so many anime shows that I still need to watch or continue watching.
During my therapy session today, the topic of Alexis embarking on a road trip later this year arose. While I’m comfortable with the idea, I can’t help but worry about my little girl, who isn’t so little anymore. We also delved into the concept that certain situations can trigger emotions and reactions that may not be directly related. Given that I experienced a panic attack in the library yesterday, it’s possible that I was triggered by something, although I’m unsure what that may have been.
Today, I had too many distractions. I slept in, couldn’t get my laptop hooked up to Tommy’s monitor, had lunch, went to therapy, and walked to get the mail (because Kel’s car is dead). I feel I didn’t get much done today. Coding was better today, but I just felt that I didn’t have enough time. Hopefully, tomorrow will be a more productive day for me.
JavaScript notes…
——————————
Statistics Calculator steps 36 – 45
Step 36
Add the logic for calculating and displaying the range to your calculate function.
const mean = getMean(numbers); const median = getMedian(numbers); const mode = getMode(numbers); const range = getRange(numbers); document.querySelector("#mean").textContent = mean; document.querySelector("#median").textContent = median; document.querySelector("#mode").textContent = mode; document.querySelector("#range").textContent = range;
Step 37
The variance of a series represents how much the data deviates from the mean, and can be used to determine how spread out the data are. The variance is calculated in a few steps.
Start by declaring a getVariance function that takes an array parameter. Within that function, declare a mean variable and assign it the value of the getMean function, passing array as the argument.
const getVariance = (array) => { const mean = getMean(array); }
Step 38
The next step is to calculate how far each element is from the mean. Declare a differences variable, and assign it the value of array.map(). For the callback, return the value of el minus mean.
const getVariance = (array) => { const mean = getMean(array); const differences = array.map(el => el - mean); }
Step 39
The next step is to square each of the differences. To square a value, you can use the ** operator. For example, 3 ** 2 would return 9.
Declare a squaredDifferences variable, and assign it the value of differences.map(). For the callback, return the value of el squared.
const getVariance = (array) => { const mean = getMean(array); const differences = array.map( el => el - mean ); const squaredDifferences = differences.map(el => el ** 2); }
Step 40
Next, you need to take the sum of the squared differences.
Declare a sumSquaredDifferences variable, and assign it the value of squaredDifferences.reduce(). For the callback, return the sum of acc and el. Remember to set the initial value to 0
const getVariance = (array) => { const mean = getMean(array); const differences = array.map( el => el - mean ); const squaredDifferences = differences.map( el => el ** 2 ); const sumSquaredDifferences = squaredDifferences.reduce((acc, el) => acc + el, 0); }
Step 41
With two .map() calls and a .reduce() call, you’re creating extra arrays and iterating more times than needed. You should move all of the logic into the .reduce() call to save time and memory.
Remove the differences, squaredDifferences, and sumSquaredDifferences variables (and their values). Declare a variance variable, and assign it the value of array.reduce(). For the callback, pass in your standard acc and el parameters, but leave the function body empty for now. Don’t forget to set the initial value to 0.
const getVariance = (array) => { const mean = getMean(array); const variance = array.reduce((acc, el) => { }, 0) }
Step 42
Within your empty .reduce() callback, declare a variable difference and set it to the value of el minus mean. Then declare a squared variable, and set it to the value of difference to the power of 2. Finally, return the value of acc plus squared.
const getVariance = (array) => { const mean = getMean(array); const variance = array.reduce((acc, el) => { const difference = el - mean; const squared = difference ** 2; return acc + squared; }, 0); }
Step 43
The final step in calculating the variance is to divide the sum of the squared differences by the count of numbers.
Divide your .reduce() call by the length of the array (in your variance declaration). Then, return variance.
const getVariance = (array) => { const mean = getMean(array); const variance = array.reduce((acc, el) => { const difference = el - mean; const squared = difference ** 2; return acc + squared; }, 0) / array.length; return variance; }
Step 44
Add your new getVariance function to the calculate function, and update the respective HTML element.
const mean = getMean(numbers); const median = getMedian(numbers); const mode = getMode(numbers); const range = getRange(numbers); const variance = getVariance(numbers); document.querySelector("#mean").textContent = mean; document.querySelector("#median").textContent = median; document.querySelector("#mode").textContent = mode; document.querySelector("#range").textContent = range; document.querySelector("#variance").textContent = variance;
Step 45
Your final calculation is the standard deviation, which is the square root of the variance.
Begin by declaring a getStandardDeviation function, with the array parameter. In the function body, declare a variance variable and assign it the variance of the array.
const getStandardDeviation = (array) => { const variance = getVariance(array); }