1var items = ['réservé', 'premier', 'communiqué', 'café', 'adieu', 'éclair'];
2items.sort(function (a, b) {
3 return a.localeCompare(b); //using String.prototype.localCompare()
4});
5
6// items is ['adieu', 'café', 'communiqué', 'éclair', 'premier', 'réservé']
1//sort array alphabetically
2objArray.sort(function(a, b) {
3 return a.localeCompare(b);
4});
1var items = ['réservé', 'premier', 'communiqué', 'café', 'adieu', 'éclair'];
2items.sort((a, b) =>
3 a.localeCompare(b)//using String.prototype.localCompare()
4);
1// function that returns a string in alphabetical order
2function reorderStr(str) {
3 return [...str].sort().join('');
4}
5console.log(reorderStr("hacker")); //"acehkr"
6console.log(reorderStr("javascript"));//"aacijprstv"