Hi guys.
Can you explain how does median effects on sorting numbers, when I’m using another array? when i silent my median code, the arrays sorting will be like the first time.
with median:
actually i learned that .sort() method can mutate original array and i didn’t know about it. In the next steps we used .slice() before sort, it made a shallow copy from array and didn’t mutate the original array.
But I need your help for another question.
Can you explain me about this line on step 36?
We didn’t learn about new Set & Object.value & .size.
if (new Set(Object.values(counts)).size === 1) {
return null;
}
I know this can delete [1, 1, 1] object value. but how?
html full code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="./styles.css" />
<script src="./script.js"></script>
<title>Statistics Calculator</title>
</head>
<body>
<h1>Statistics Calculator</h1>
<p>Enter a list of comma-separated numbers.</p>
<form onsubmit="calculate(); return false;">
<label for="numbers">Numbers:</label>
<input type="text" name="numbers" id="numbers" />
<button type="submit">Calculate</button>
</form>
<div class="results">
<p>
The <dfn>mean</dfn> of a list of numbers is the average, calculated by
taking the sum of all numbers and dividing that by the count of numbers.
</p>
<p class="bold">Mean: <span id="mean"></span></p>
<p>
The <dfn>median</dfn> of a list of numbers is the number that appears in
the middle of the list, when sorted from least to greatest.
</p>
<p class="bold">Median: <span id="median"></span></p>
<p>
The <dfn>mode</dfn> of a list of numbers is the number that appears most
often in the list.
</p>
<p class="bold">Mode: <span id="mode"></span></p>
<p>
The <dfn>range</dfn> of a list of numbers is the difference between the
largest and smallest numbers in the list.
</p>
<p class="bold">Range: <span id="range"></span></p>
<p>
The <dfn>variance</dfn> of a list of numbers measures how far the values
are from the mean, on average.
</p>
<p class="bold">Variance: <span id="variance"></span></p>
<p>
The <dfn>standard deviation</dfn> of a list of numbers is the square
root of the variance.
</p>
<p class="bold">
Standard Deviation: <span id="standardDeviation"></span>
</p>
</div>
</body>
</html>
a Set has the characteristic that it can’t have duplicated elements, so if you do new Set([1, 1, 1]) the result is a set {1}.
The size is similar to the length property on arrays, it returns 1 because there is only one element
Object.values gives back an array with only the values in the object.
In total, if the object counts has the values of the key/value pairs all the same value, then return null