I need to sort this array
['$', 'z', 7, 'a', 1, '%', '.', 5, '% hello', ' ', 'f', '^' , '-', '_']
as
[ , %, % hello, _, -, ., ^, $, 1, 5, 7, a, f, z]
But the result I'm getting is
[ , _, -, ., %, % hello, ^, $, 1, 5, 7, a, f, z]
Is there any way to create custom collator? In this case, is it possible to get the position of any specific character or symbol say '%' before other symbols?
var collator = Intl.Collator();
var letters = ['$', 'z', 7, 'a', 1, '%', '.', 5, '% hello', ' ', 'f', '^' , '-', '_'];
console.log(letters.sort(collator.compare));