Does anyone know why it is illegal to call Array.sort on a string?
[].sort.call("some string")
But is calling Array.map, Array.reduce or Array.filter ok?
[].map.call("some string", function(x){ return String.fromCharCode(x.charCodeAt(0)+1); }); // ["t", "p", "n", "f", "!", "t", "u", "s", "j", "o", "h"] [].reduce.call("some string", function(a, b){ return (+a === a ? a : a.charCodeAt(0)) + b.charCodeAt(0); }) // 1131 [].filter.call("some string", function(x){ return x.charCodeAt(0) > 110; }) // ["s", "o", "s", "t", "r"]
source share