generated from tc39/template-for-proposals
-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Instead of providing just a specialised function that would be used like
array.sort(String.comparingByCodePoints);it would be similarly ergonomic and more generally applicable to do something like
array.sort(Iterator.comparingBy(s => s.codePoints()));assuming we had (roughly)
String.prototype.codePoints = function() {
return this[Symbol.iterator]().map(c => c.codePointAt(0)));
};and also (roughly)
Iterator.comparingBy = getIter => {
const NIL = {};
return (a, b) => {
let as = getIter(a);
let bs = getIter(b);
for (let [a, b] of Iterator.zip([as, bs], { mode: "longest", padding: [NIL, NIL] )) {
if (a === NIL) return -1;
if (b === NIL) return 1;
if (a < b) return -1;
if (b < a) return 1;
}
return 0;
};
}Metadata
Metadata
Assignees
Labels
No labels