diff --git a/files/en-us/web/javascript/reference/global_objects/array/sort/index.html b/files/en-us/web/javascript/reference/global_objects/array/sort/index.html index 74344206f430f96..57a3ae57bd1703e 100644 --- a/files/en-us/web/javascript/reference/global_objects/array/sort/index.html +++ b/files/en-us/web/javascript/reference/global_objects/array/sort/index.html @@ -221,15 +221,15 @@
// the array to be sorted -var list = ['Delta', 'alpha', 'CHARLIE', 'bravo']; +const in = ['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() }; +const mapped = in.map((v, i) => { + return { i, value: someSlowOperation(v) }; }) // sorting the mapped array containing the reduced values -mapped.sort(function(a, b) { +mapped.sort((a, b) => { if (a.value > b.value) { return 1; } @@ -239,10 +239,7 @@Sorting with map
return 0; }); -// container for the resulting order -var result = mapped.map(function(el){ - return list[el.index]; -}); +const result = mapped.map(v => in[v.i]);