Code change:
<section id='description'> The <code>sort</code> method sorts the elements of an array according to the callback function. For example: <del> <blockquote>function ascendingOrder(arr) {<br>&nbsp;&nbsp;return arr.sort(function(a, b) {<br>&nbsp;&nbsp;&nbsp;&nbsp;return a - b;<br>&nbsp;&nbsp;});<br>}<br>ascendingOrder([1, 5, 2, 3, 4]);<br>// Returns [1, 2, 3, 4, 5]<br><br>function reverseAlpha(arr) {<br>&nbsp;&nbsp;return arr.sort(function(a, b) {<br>&nbsp;&nbsp;&nbsp;&nbsp;return a < b;<br>&nbsp;&nbsp;});<br>}<br>reverseAlpha(['l', 'h', 'z', 'b', 's']);<br>// Returns ['z', 's', 'l', 'h', 'b']</blockquote> </del> <ins> <blockquote>function ascendingOrder(arr) {<br>&nbsp;&nbsp;return arr.sort(function(a, b) {<br>&nbsp;&nbsp;&nbsp;&nbsp;return a - b;<br>&nbsp;&nbsp;});<br>}<br>ascendingOrder([1, 5, 2, 3, 4]);<br>// Returns [1, 2, 3, 4, 5]<br><br>function reverseAlpha(arr) {<br>&nbsp;&nbsp;return arr.sort(function(a, b) {<br>&nbsp;&nbsp;&nbsp;&nbsp;return a === b ? 0 : a < b ? : 1 : -1;<br>&nbsp;&nbsp;});<br>}<br>reverseAlpha(['l', 'h', 'z', 'b', 's']);<br>// Returns ['z', 's', 'l', 'h', 'b']</blockquote> </ins> Note: It's encouraged to provide a callback function to specify how to sort the array items. JavaScript's default sorting method is by string Unicode point value, which may return unexpected results. </section>

Related discussion:
text: <!-- NOTE: If you're reporting a security issue, don't create a GitHub issue. Instead, email We will look into it immediately. --Describe your problem and how to reproduce it: This challenge has an example of sorting like this: ` This example uses a bad compare function. In recent changes to Chrome the following example no longer properly sorts the array: The compare function needs to return a number to be able to sort an array properly. This can be fixed by changing the compare function to return a number: Add a Link to the page with the problem: Tell us about your browser and operating system: Browser Name: Chrome Browser Version: 70 Operating System: Windows 10
The above return statement only returns 1 or -1. To preserve the original order for elements which have the same value, you need to test for the condition where they are equal. For example, to preserve an elements original order when equal, you would write: While in this particular example, you may not be able to see the difference, I will show a different example below, where the difference can be seen. Let's say you have the following array of objects: The 2nd and fifth elements have the same letter, but they are in different positions. Let's say you want to sort the objects in alphabetical order and preserve the original sort order of the elements with the same letter (in this case those with letter 'b'). This means, after the sort, letters should look like: If you just create the following sort function without specifying a return value of 0 when the letters are equal, it would not sort correctly in the new version of Chrome: The above produces: instead of the correct version: To preserve the original sort order for objects with the same letter, you must use the following sort function: I think the example should reflect the better practice of specifying a return value of 0 for elements which are equal in value. This matches the actual requirements of the compare function of returning a value of 0, -1, or 1, so I believe the example should be written like:
I am interested working on this issue
Although the example used in the original text doesn't require ordering I agree adding would be fine. As much as I like ternaries, I'm not in favor of nested ternaries. As a general rule they . If possible I'd keep the text challenge clean and readable.