How to compare two words by ASCII Codes in JavaScript?
I need a function that compares two words based on the sum of their ASCII codes and returns the word with the smaller ASCII sum.
1 Answer
This function returns exactly what is required
its returns the word with the smaller ASCII sum
const asciiSort = ([a, b]) => {
let r = (t, c) => t + c.charCodeAt(0);
return [...a].reduce(r, 0) < [...b].reduce(r, 0) ? a : b;
}
answer Link