showing results for - "mapsort"
Bay
09 May 2019
1// the array to be sorted
2var list = ['Delta', 'alpha', 'CHARLIE', 'bravo'];
3
4// temporary array holds objects with position and sort-value
5var mapped = list.map(function(el, i) {
6  return { index: i, value: el.toLowerCase() };
7})
8
9// sorting the mapped array containing the reduced values
10mapped.sort(function(a, b) {
11  if (a.value > b.value) {
12    return 1;
13  }
14  if (a.value < b.value) {
15    return -1;
16  }
17  return 0;
18});
19
20// container for the resulting order
21var result = mapped.map(function(el){
22  return list[el.index];
23});
24
similar questions
mapdispatchtoprops
queries leading to this page
mapsortmapsort