From bcdaf321c2a3bd733ad845c83cf428a312f0bd44 Mon Sep 17 00:00:00 2001 From: Gagan Bhullar Date: Tue, 20 Aug 2024 10:50:49 -0600 Subject: [PATCH] fix(curriculum): sort wrong validation (#55896) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Naomi the Technomancer Co-authored-by: Lasse Jørgensen <28780271+lasjorg@users.noreply.github.com> --- .../meta.json | 72 +++++----- .../63508c898d753754757bd5e3.md | 2 +- .../635090f47eb6d9563a6fed05.md | 13 +- .../6352e79d15aae30fac58f48e.md | 12 +- .../6352e80e024e89111600edfb.md | 12 +- .../6352e93db104661305c5f658.md | 12 +- .../6352e96d2604f813c656750b.md | 16 +-- .../6352ea3a5b79e614ee2282fd.md | 12 +- .../6352ebd3ab962c168a122e85.md | 12 +- .../6352ec8b9c70fd17b8c7ba3f.md | 12 +- .../6352ecef9f045519063da9b3.md | 12 +- .../6352edee8a4de01ad693f0e4.md | 12 +- .../6352ee566a59d31d24bde74b.md | 12 +- .../6352f09b1e53a420e7873344.md | 12 +- .../6352f179bdca23221298a5ba.md | 12 +- .../6352f2526dccb523150b64fb.md | 12 +- .../6352f2a24eb71b24284ca2b6.md | 12 +- .../6352faf71a9db52631864634.md | 12 +- .../6352fbb93a91a8272f838d42.md | 12 +- .../6352fcb156834128001ea945.md | 12 +- .../6352fce75b2d3b2924930f1e.md | 12 +- .../6352fe473d53592a40ae403b.md | 12 +- .../6352fed209792d2b89e92ea1.md | 12 +- .../6352ff27e0e51b2c7dce0010.md | 12 +- .../6352ffe4cfafa72d595a0007.md | 12 +- .../6353004b235d7a2e0b913f2b.md | 12 +- .../6353024f5eab012fa2f57eec.md | 12 +- .../6353028147d3c7309017216a.md | 12 +- .../635302be760d6031d11a06cd.md | 12 +- .../6374249d3fbf2a5b079ba036.md | 12 +- .../65aac0678d51b3f1a0cb8061.md | 12 +- .../65c4dc57418fd6bfc710d61d.md | 12 +- .../65ca2d0625aa3a3201067f70.md | 12 +- .../65e62efde0592ec4b4bb6a69.md | 12 +- .../65f83a7ca7047318e3ccff7c.md | 12 +- .../66c395a16c3ff33dc6f8e7c0.md | 133 ++++++++++++++++++ 36 files changed, 375 insertions(+), 233 deletions(-) create mode 100644 curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/66c395a16c3ff33dc6f8e7c0.md diff --git a/curriculum/challenges/_meta/learn-advanced-array-methods-by-building-a-statistics-calculator/meta.json b/curriculum/challenges/_meta/learn-advanced-array-methods-by-building-a-statistics-calculator/meta.json index 25e9766e0e9..e06d3751b14 100644 --- a/curriculum/challenges/_meta/learn-advanced-array-methods-by-building-a-statistics-calculator/meta.json +++ b/curriculum/challenges/_meta/learn-advanced-array-methods-by-building-a-statistics-calculator/meta.json @@ -109,136 +109,140 @@ "title": "Step 25" }, { - "id": "635090f47eb6d9563a6fed05", + "id": "66c395a16c3ff33dc6f8e7c0", "title": "Step 26" }, { - "id": "6352e79d15aae30fac58f48e", + "id": "635090f47eb6d9563a6fed05", "title": "Step 27" }, { - "id": "6352e80e024e89111600edfb", + "id": "6352e79d15aae30fac58f48e", "title": "Step 28" }, { - "id": "6352e93db104661305c5f658", + "id": "6352e80e024e89111600edfb", "title": "Step 29" }, { - "id": "6352e96d2604f813c656750b", + "id": "6352e93db104661305c5f658", "title": "Step 30" }, { - "id": "65aac0678d51b3f1a0cb8061", + "id": "6352e96d2604f813c656750b", "title": "Step 31" }, { - "id": "65c4dc57418fd6bfc710d61d", + "id": "65aac0678d51b3f1a0cb8061", "title": "Step 32" }, { - "id": "65ca2d0625aa3a3201067f70", + "id": "65c4dc57418fd6bfc710d61d", "title": "Step 33" }, { - "id": "65e62efde0592ec4b4bb6a69", + "id": "65ca2d0625aa3a3201067f70", "title": "Step 34" }, { - "id": "65f83a7ca7047318e3ccff7c", + "id": "65e62efde0592ec4b4bb6a69", "title": "Step 35" }, { - "id": "6352ea3a5b79e614ee2282fd", + "id": "65f83a7ca7047318e3ccff7c", "title": "Step 36" }, { - "id": "6352ebd3ab962c168a122e85", + "id": "6352ea3a5b79e614ee2282fd", "title": "Step 37" }, { - "id": "6352ec8b9c70fd17b8c7ba3f", + "id": "6352ebd3ab962c168a122e85", "title": "Step 38" }, { - "id": "6352ecef9f045519063da9b3", + "id": "6352ec8b9c70fd17b8c7ba3f", "title": "Step 39" }, { - "id": "6352edee8a4de01ad693f0e4", + "id": "6352ecef9f045519063da9b3", "title": "Step 40" }, { - "id": "6352ee566a59d31d24bde74b", + "id": "6352edee8a4de01ad693f0e4", "title": "Step 41" }, { - "id": "6352f09b1e53a420e7873344", + "id": "6352ee566a59d31d24bde74b", "title": "Step 42" }, { - "id": "6352f179bdca23221298a5ba", + "id": "6352f09b1e53a420e7873344", "title": "Step 43" }, { - "id": "6352f2526dccb523150b64fb", + "id": "6352f179bdca23221298a5ba", "title": "Step 44" }, { - "id": "6352f2a24eb71b24284ca2b6", + "id": "6352f2526dccb523150b64fb", "title": "Step 45" }, { - "id": "6352faf71a9db52631864634", + "id": "6352f2a24eb71b24284ca2b6", "title": "Step 46" }, { - "id": "6352fbb93a91a8272f838d42", + "id": "6352faf71a9db52631864634", "title": "Step 47" }, { - "id": "6352fcb156834128001ea945", + "id": "6352fbb93a91a8272f838d42", "title": "Step 48" }, { - "id": "6352fce75b2d3b2924930f1e", + "id": "6352fcb156834128001ea945", "title": "Step 49" }, { - "id": "6352fe473d53592a40ae403b", + "id": "6352fce75b2d3b2924930f1e", "title": "Step 50" }, { - "id": "6352fed209792d2b89e92ea1", + "id": "6352fe473d53592a40ae403b", "title": "Step 51" }, { - "id": "6352ff27e0e51b2c7dce0010", + "id": "6352fed209792d2b89e92ea1", "title": "Step 52" }, { - "id": "6352ffe4cfafa72d595a0007", + "id": "6352ff27e0e51b2c7dce0010", "title": "Step 53" }, { - "id": "6353004b235d7a2e0b913f2b", + "id": "6352ffe4cfafa72d595a0007", "title": "Step 54" }, { - "id": "6353024f5eab012fa2f57eec", + "id": "6353004b235d7a2e0b913f2b", "title": "Step 55" }, { - "id": "6353028147d3c7309017216a", + "id": "6353024f5eab012fa2f57eec", "title": "Step 56" }, + { + "id": "6353028147d3c7309017216a", + "title": "Step 57 " + }, { "id": "635302be760d6031d11a06cd", - "title": "Step 57" + "title": "Step 58" }, { "id": "6374249d3fbf2a5b079ba036", - "title": "Step 58" + "title": "Step 59" } ] -} +} \ No newline at end of file diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/63508c898d753754757bd5e3.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/63508c898d753754757bd5e3.md index b4bea0fa5d9..3e06d780e1d 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/63508c898d753754757bd5e3.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/63508c898d753754757bd5e3.md @@ -7,7 +7,7 @@ dashedName: step-21 # --description-- -By default, the `.sort()` method converts the elements of an array into strings, then sorts them alphabetically. This works well for strings, but not so well for numbers. For example, `10` comes before `2` when sorted as strings, but `2` comes before `10` when sorted as numbers. +By default, the `.sort()` method converts the elements of an array into strings, then sorts them alphabetically. The `.sort()` method mutates the original array. This works well for strings, but not so well for numbers. For example, `10` comes before `2` when sorted as strings, but `2` comes before `10` when sorted as numbers. To fix this, you can pass in a callback function to the `.sort()` method. This function takes two arguments, which represent the two elements being compared. The function should return a value less than `0` if the first element should come before the second element, a value greater than `0` if the first element should come after the second element, and `0` if the two elements should remain in their current positions. diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/635090f47eb6d9563a6fed05.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/635090f47eb6d9563a6fed05.md index 02ad908203d..68bb5be9642 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/635090f47eb6d9563a6fed05.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/635090f47eb6d9563a6fed05.md @@ -1,15 +1,15 @@ --- id: 635090f47eb6d9563a6fed05 -title: Step 26 +title: Step 27 challengeType: 0 -dashedName: step-26 +dashedName: step-27 --- # --description-- Now it is time to apply what you have learned to the `getMedian` function. -Inside your `getMedian` function, check if the length of `array` is even. If it is, find the middle two numbers, calculate their mean, and return the result. If the length of `array` is odd, return the middle number. +Inside your `getMedian` function, check if the length of `sorted` is even. If it is, find the middle two numbers, calculate their mean, and return the result. If the length of `sorted` is odd, return the middle number. Make sure to work with the `sorted` array to find the middle numbers. @@ -17,6 +17,11 @@ Also if you need help, refer back to the previous few steps to see how to find t # --hints-- +Your `getMedian` function should use `sorted` array. + +```js +assert.equal(getMedian.toString().match(/array/g).length, 2); +``` Your `getMedian` function should return the mean of the middle two numbers if the array length is even. @@ -123,7 +128,7 @@ const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length --fcc-editable-region-- const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); } --fcc-editable-region-- diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352e79d15aae30fac58f48e.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352e79d15aae30fac58f48e.md index 2f4c5efc335..8506014ba23 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352e79d15aae30fac58f48e.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352e79d15aae30fac58f48e.md @@ -1,8 +1,8 @@ --- id: 6352e79d15aae30fac58f48e -title: Step 27 +title: Step 28 challengeType: 0 -dashedName: step-27 +dashedName: step-28 --- # --description-- @@ -121,11 +121,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352e80e024e89111600edfb.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352e80e024e89111600edfb.md index 8168344a750..df6b5d55059 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352e80e024e89111600edfb.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352e80e024e89111600edfb.md @@ -1,8 +1,8 @@ --- id: 6352e80e024e89111600edfb -title: Step 28 +title: Step 29 challengeType: 0 -dashedName: step-28 +dashedName: step-29 --- # --description-- @@ -119,11 +119,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352e93db104661305c5f658.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352e93db104661305c5f658.md index f4348f6e172..6cb8402fb69 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352e93db104661305c5f658.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352e93db104661305c5f658.md @@ -1,8 +1,8 @@ --- id: 6352e93db104661305c5f658 -title: Step 29 +title: Step 30 challengeType: 0 -dashedName: step-29 +dashedName: step-30 --- # --description-- @@ -136,11 +136,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352e96d2604f813c656750b.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352e96d2604f813c656750b.md index 44be8b92954..eb9991f1d58 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352e96d2604f813c656750b.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352e96d2604f813c656750b.md @@ -1,8 +1,8 @@ --- id: 6352e96d2604f813c656750b -title: Step 30 +title: Step 31 challengeType: 0 -dashedName: step-30 +dashedName: step-31 --- # --description-- @@ -108,14 +108,14 @@ input { ```js const getMean = array => array.reduce((acc, el) => acc + el, 0) / array.length; -const getMedian = array => { - const sorted = array.sort((a, b) => a - b); +const getMedian = (array) => { + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; -}; +} const getMode = array => { const counts = {}; diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ea3a5b79e614ee2282fd.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ea3a5b79e614ee2282fd.md index 8c668a37b40..afb7abc5efa 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ea3a5b79e614ee2282fd.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ea3a5b79e614ee2282fd.md @@ -1,8 +1,8 @@ --- id: 6352ea3a5b79e614ee2282fd -title: Step 36 +title: Step 37 challengeType: 0 -dashedName: step-36 +dashedName: step-37 --- # --description-- @@ -130,11 +130,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ebd3ab962c168a122e85.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ebd3ab962c168a122e85.md index 705008d4632..ce5d0adc69c 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ebd3ab962c168a122e85.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ebd3ab962c168a122e85.md @@ -1,8 +1,8 @@ --- id: 6352ebd3ab962c168a122e85 -title: Step 37 +title: Step 38 challengeType: 0 -dashedName: step-37 +dashedName: step-38 --- # --description-- @@ -121,11 +121,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ec8b9c70fd17b8c7ba3f.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ec8b9c70fd17b8c7ba3f.md index 5c0ae57b935..39c6ca85977 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ec8b9c70fd17b8c7ba3f.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ec8b9c70fd17b8c7ba3f.md @@ -1,8 +1,8 @@ --- id: 6352ec8b9c70fd17b8c7ba3f -title: Step 38 +title: Step 39 challengeType: 0 -dashedName: step-38 +dashedName: step-39 --- # --description-- @@ -129,11 +129,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ecef9f045519063da9b3.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ecef9f045519063da9b3.md index 40edd9e19c8..5c427b985f8 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ecef9f045519063da9b3.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ecef9f045519063da9b3.md @@ -1,8 +1,8 @@ --- id: 6352ecef9f045519063da9b3 -title: Step 39 +title: Step 40 challengeType: 0 -dashedName: step-39 +dashedName: step-40 --- # --description-- @@ -115,11 +115,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352edee8a4de01ad693f0e4.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352edee8a4de01ad693f0e4.md index a493399f414..db30297edcc 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352edee8a4de01ad693f0e4.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352edee8a4de01ad693f0e4.md @@ -1,8 +1,8 @@ --- id: 6352edee8a4de01ad693f0e4 -title: Step 40 +title: Step 41 challengeType: 0 -dashedName: step-40 +dashedName: step-41 --- # --description-- @@ -119,11 +119,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ee566a59d31d24bde74b.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ee566a59d31d24bde74b.md index 86ea1bc1ad8..001ae7649eb 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ee566a59d31d24bde74b.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ee566a59d31d24bde74b.md @@ -1,8 +1,8 @@ --- id: 6352ee566a59d31d24bde74b -title: Step 41 +title: Step 42 challengeType: 0 -dashedName: step-41 +dashedName: step-42 --- # --description-- @@ -121,11 +121,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352f09b1e53a420e7873344.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352f09b1e53a420e7873344.md index d0eea0a75ca..44fbcae0d4d 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352f09b1e53a420e7873344.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352f09b1e53a420e7873344.md @@ -1,8 +1,8 @@ --- id: 6352f09b1e53a420e7873344 -title: Step 42 +title: Step 43 challengeType: 0 -dashedName: step-42 +dashedName: step-43 --- # --description-- @@ -113,11 +113,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352f179bdca23221298a5ba.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352f179bdca23221298a5ba.md index 45f19daffa2..a7e6eafe8f2 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352f179bdca23221298a5ba.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352f179bdca23221298a5ba.md @@ -1,8 +1,8 @@ --- id: 6352f179bdca23221298a5ba -title: Step 43 +title: Step 44 challengeType: 0 -dashedName: step-43 +dashedName: step-44 --- # --description-- @@ -149,11 +149,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352f2526dccb523150b64fb.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352f2526dccb523150b64fb.md index d71852a3b35..3d354adb0d8 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352f2526dccb523150b64fb.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352f2526dccb523150b64fb.md @@ -1,8 +1,8 @@ --- id: 6352f2526dccb523150b64fb -title: Step 44 +title: Step 45 challengeType: 0 -dashedName: step-44 +dashedName: step-45 --- # --description-- @@ -113,11 +113,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352f2a24eb71b24284ca2b6.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352f2a24eb71b24284ca2b6.md index 6033acf2f5a..73b323f2a04 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352f2a24eb71b24284ca2b6.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352f2a24eb71b24284ca2b6.md @@ -1,8 +1,8 @@ --- id: 6352f2a24eb71b24284ca2b6 -title: Step 45 +title: Step 46 challengeType: 0 -dashedName: step-45 +dashedName: step-46 --- # --description-- @@ -127,11 +127,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352faf71a9db52631864634.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352faf71a9db52631864634.md index cf883b6e1bd..3de2c788a5d 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352faf71a9db52631864634.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352faf71a9db52631864634.md @@ -1,8 +1,8 @@ --- id: 6352faf71a9db52631864634 -title: Step 46 +title: Step 47 challengeType: 0 -dashedName: step-46 +dashedName: step-47 --- # --description-- @@ -125,11 +125,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352fbb93a91a8272f838d42.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352fbb93a91a8272f838d42.md index 2a27e641fcf..2b36ce01542 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352fbb93a91a8272f838d42.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352fbb93a91a8272f838d42.md @@ -1,8 +1,8 @@ --- id: 6352fbb93a91a8272f838d42 -title: Step 47 +title: Step 48 challengeType: 0 -dashedName: step-47 +dashedName: step-48 --- # --description-- @@ -133,11 +133,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352fcb156834128001ea945.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352fcb156834128001ea945.md index d48a90cb574..ed45d66a02a 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352fcb156834128001ea945.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352fcb156834128001ea945.md @@ -1,8 +1,8 @@ --- id: 6352fcb156834128001ea945 -title: Step 48 +title: Step 49 challengeType: 0 -dashedName: step-48 +dashedName: step-49 --- # --description-- @@ -127,11 +127,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352fce75b2d3b2924930f1e.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352fce75b2d3b2924930f1e.md index 25fc914cc5e..480ec5f8155 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352fce75b2d3b2924930f1e.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352fce75b2d3b2924930f1e.md @@ -1,8 +1,8 @@ --- id: 6352fce75b2d3b2924930f1e -title: Step 49 +title: Step 50 challengeType: 0 -dashedName: step-49 +dashedName: step-50 --- # --description-- @@ -151,11 +151,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352fe473d53592a40ae403b.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352fe473d53592a40ae403b.md index 0aa6205db6f..b690f70f478 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352fe473d53592a40ae403b.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352fe473d53592a40ae403b.md @@ -1,8 +1,8 @@ --- id: 6352fe473d53592a40ae403b -title: Step 50 +title: Step 51 challengeType: 0 -dashedName: step-50 +dashedName: step-51 --- # --description-- @@ -137,11 +137,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352fed209792d2b89e92ea1.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352fed209792d2b89e92ea1.md index 2e133af9c7e..bb4f2879211 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352fed209792d2b89e92ea1.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352fed209792d2b89e92ea1.md @@ -1,8 +1,8 @@ --- id: 6352fed209792d2b89e92ea1 -title: Step 51 +title: Step 52 challengeType: 0 -dashedName: step-51 +dashedName: step-52 --- # --description-- @@ -115,11 +115,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ff27e0e51b2c7dce0010.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ff27e0e51b2c7dce0010.md index 09ab6f7cf5a..2319b87f93e 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ff27e0e51b2c7dce0010.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ff27e0e51b2c7dce0010.md @@ -1,8 +1,8 @@ --- id: 6352ff27e0e51b2c7dce0010 -title: Step 52 +title: Step 53 challengeType: 0 -dashedName: step-52 +dashedName: step-53 --- # --description-- @@ -113,11 +113,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ffe4cfafa72d595a0007.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ffe4cfafa72d595a0007.md index fde6e2e1d0e..6107093f789 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ffe4cfafa72d595a0007.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6352ffe4cfafa72d595a0007.md @@ -1,8 +1,8 @@ --- id: 6352ffe4cfafa72d595a0007 -title: Step 53 +title: Step 54 challengeType: 0 -dashedName: step-53 +dashedName: step-54 --- # --description-- @@ -127,11 +127,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6353004b235d7a2e0b913f2b.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6353004b235d7a2e0b913f2b.md index 9a5202c8e9c..9933b3b8dec 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6353004b235d7a2e0b913f2b.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6353004b235d7a2e0b913f2b.md @@ -1,8 +1,8 @@ --- id: 6353004b235d7a2e0b913f2b -title: Step 54 +title: Step 55 challengeType: 0 -dashedName: step-54 +dashedName: step-55 --- # --description-- @@ -136,11 +136,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6353024f5eab012fa2f57eec.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6353024f5eab012fa2f57eec.md index 926956a5da8..4cc67258312 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6353024f5eab012fa2f57eec.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6353024f5eab012fa2f57eec.md @@ -1,8 +1,8 @@ --- id: 6353024f5eab012fa2f57eec -title: Step 55 +title: Step 56 challengeType: 0 -dashedName: step-55 +dashedName: step-56 --- # --description-- @@ -109,11 +109,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6353028147d3c7309017216a.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6353028147d3c7309017216a.md index ab058c2de79..c9bb7d79f67 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6353028147d3c7309017216a.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6353028147d3c7309017216a.md @@ -1,8 +1,8 @@ --- id: 6353028147d3c7309017216a -title: Step 56 +title: Step 57 challengeType: 0 -dashedName: step-56 +dashedName: step-57 --- # --description-- @@ -107,11 +107,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/635302be760d6031d11a06cd.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/635302be760d6031d11a06cd.md index 552d6b1fc35..b96c76232ae 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/635302be760d6031d11a06cd.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/635302be760d6031d11a06cd.md @@ -1,8 +1,8 @@ --- id: 635302be760d6031d11a06cd -title: Step 57 +title: Step 58 challengeType: 0 -dashedName: step-57 +dashedName: step-58 --- # --description-- @@ -113,11 +113,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6374249d3fbf2a5b079ba036.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6374249d3fbf2a5b079ba036.md index 3960bcc7333..22f695deff6 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6374249d3fbf2a5b079ba036.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/6374249d3fbf2a5b079ba036.md @@ -1,8 +1,8 @@ --- id: 6374249d3fbf2a5b079ba036 -title: Step 58 +title: Step 59 challengeType: 0 -dashedName: step-58 +dashedName: step-59 --- # --description-- @@ -122,11 +122,11 @@ const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length --fcc-editable-region-- const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } --fcc-editable-region-- diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/65aac0678d51b3f1a0cb8061.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/65aac0678d51b3f1a0cb8061.md index 70baccced66..010ed0d47ad 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/65aac0678d51b3f1a0cb8061.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/65aac0678d51b3f1a0cb8061.md @@ -1,8 +1,8 @@ --- id: 65aac0678d51b3f1a0cb8061 -title: Step 31 +title: Step 32 challengeType: 0 -dashedName: step-31 +dashedName: step-32 --- # --description-- @@ -115,11 +115,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/65c4dc57418fd6bfc710d61d.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/65c4dc57418fd6bfc710d61d.md index 3caed9a9936..db40208dd3d 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/65c4dc57418fd6bfc710d61d.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/65c4dc57418fd6bfc710d61d.md @@ -1,8 +1,8 @@ --- id: 65c4dc57418fd6bfc710d61d -title: Step 32 +title: Step 33 challengeType: 0 -dashedName: step-32 +dashedName: step-33 --- # --description-- @@ -115,11 +115,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/65ca2d0625aa3a3201067f70.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/65ca2d0625aa3a3201067f70.md index d6091a606d2..423f5e771e9 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/65ca2d0625aa3a3201067f70.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/65ca2d0625aa3a3201067f70.md @@ -1,8 +1,8 @@ --- id: 65ca2d0625aa3a3201067f70 -title: Step 33 +title: Step 34 challengeType: 0 -dashedName: step-33 +dashedName: step-34 --- # --description-- @@ -125,11 +125,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/65e62efde0592ec4b4bb6a69.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/65e62efde0592ec4b4bb6a69.md index f8ad27c397c..0b9657f2ddf 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/65e62efde0592ec4b4bb6a69.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/65e62efde0592ec4b4bb6a69.md @@ -1,8 +1,8 @@ --- id: 65e62efde0592ec4b4bb6a69 -title: Step 34 +title: Step 35 challengeType: 0 -dashedName: step-34 +dashedName: step-35 --- # --description-- @@ -108,11 +108,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/65f83a7ca7047318e3ccff7c.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/65f83a7ca7047318e3ccff7c.md index 054a0bfb0a8..45697f4bc35 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/65f83a7ca7047318e3ccff7c.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/65f83a7ca7047318e3ccff7c.md @@ -1,8 +1,8 @@ --- id: 65f83a7ca7047318e3ccff7c -title: Step 35 +title: Step 36 challengeType: 0 -dashedName: step-35 +dashedName: step-36 --- # --description-- @@ -108,11 +108,11 @@ input { const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; const getMedian = (array) => { - const sorted = array.sort((a, b) => a - b); + const sorted = array.toSorted((a, b) => a - b); const median = - array.length % 2 === 0 - ? getMean([sorted[array.length / 2], sorted[array.length / 2 - 1]]) - : sorted[Math.floor(array.length / 2)]; + sorted.length % 2 === 0 + ? getMean([sorted[sorted.length / 2], sorted[sorted.length / 2 - 1]]) + : sorted[Math.floor(sorted.length / 2)]; return median; } diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/66c395a16c3ff33dc6f8e7c0.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/66c395a16c3ff33dc6f8e7c0.md new file mode 100644 index 00000000000..baa94fb21c8 --- /dev/null +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-advanced-array-methods-by-building-a-statistics-calculator/66c395a16c3ff33dc6f8e7c0.md @@ -0,0 +1,133 @@ +--- +id: 66c395a16c3ff33dc6f8e7c0 +title: Step 26 +challengeType: 0 +dashedName: step-26 +--- + +# --description-- + +The `.sort()` method mutates the original array - in other words, it modifies the order of the elements directly. This is generally considered bad practice, as it can result in unexpected side effects. + +Instead, you should use the `.toSorted()` method, which creates a new array. Change your `.sort()` call to `.toSorted()`. Do not modify the callback function. + +# --hints-- + +You should use `.toSorted()` instead of `.sort()`. + +```js +assert.notMatch(getMedian.toString(), /array\.sort/); +assert.match(getMedian.toString(), /array\.toSorted/); +``` + +You should not modify the callback function. + +```js +assert.match(code, /array\.toSorted\(\s*\(\s*a,\s*b\s*\)\s*=>\s*a\s*-\s*b\);?/); +``` + +# --seed-- + +## --seed-contents-- + +```html + + + + + + + + Statistics Calculator + + +

Statistics Calculator

+

Enter a list of comma-separated numbers.

+
+ + + +
+
+

+ The mean of a list of numbers is the average, calculated by + taking the sum of all numbers and dividing that by the count of numbers. +

+

Mean:

+

+ The median of a list of numbers is the number that appears in + the middle of the list, when sorted from least to greatest. +

+

Median:

+

+ The mode of a list of numbers is the number that appears most + often in the list. +

+

Mode:

+

+ The range of a list of numbers is the difference between the + largest and smallest numbers in the list. +

+

Range:

+

+ The variance of a list of numbers measures how far the values + are from the mean, on average. +

+

Variance:

+

+ The standard deviation of a list of numbers is the square + root of the variance. +

+

+ Standard Deviation: +

+
+ + +``` + +```css +body { + margin: 0; + background-color: rgb(27, 27, 50); + text-align: center; + color: #fff; +} + +button { + cursor: pointer; + background-color: rgb(59, 59, 79); + border: 3px solid white; + color: white; +} + +input { + background-color: rgb(10, 10, 35); + color: white; + border: 1px solid rgb(59, 59, 79); +} + +.bold { + font-weight: bold; +} +``` + +```js +const getMean = (array) => array.reduce((acc, el) => acc + el, 0) / array.length; + +--fcc-editable-region-- +const getMedian = (array) => { + const sorted = array.sort((a, b) => a - b); +} +--fcc-editable-region-- + +const calculate = () => { + const value = document.querySelector("#numbers").value; + const array = value.split(/,\s*/g); + const numbers = array.map(el => Number(el)).filter(el => !isNaN(el)); + + const mean = getMean(numbers); + + document.querySelector("#mean").textContent = mean; +} +```