-
Notifications
You must be signed in to change notification settings - Fork 23.1k
Closed
Description
content/files/en-us/web/javascript/reference/global_objects/array/sort/index.html
Lines 224 to 245 in 9d64d82
| var list = ['Delta', 'alpha', 'CHARLIE', 'bravo']; | |
| // temporary array holds objects with position and sort-value | |
| var mapped = list.map(function(el, i) { | |
| return { index: i, value: el.toLowerCase() }; | |
| }) | |
| // sorting the mapped array containing the reduced values | |
| mapped.sort(function(a, b) { | |
| if (a.value > b.value) { | |
| return 1; | |
| } | |
| if (a.value < b.value) { | |
| return -1; | |
| } | |
| return 0; | |
| }); | |
| // container for the resulting order | |
| var result = mapped.map(function(el){ | |
| return list[el.index]; | |
| }); |
By the library link from the article I found better explanation of this idea. I mean we should add more accent about performance, by adding a call to some expensive function.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels