DEV Community

Discussion on: Daily Challenge #205 - Consonant String Value

Collapse
 
mellen profile image
Matt Ellen • Edited

Nice! Here's my implementation:

const solve = word => word.split(/[uoiea]/)
                          .map(s => s.split('')
                                     .reduce((acc, c) => acc + (c.charCodeAt(0) - 96), 0))
                          .sort((a, b) => b-a)[0];
Collapse
 
sabbin profile image
Sabin Pandelovitch

Very nice, I wasn't aware of the c.charCodeAt(0) - 96 rule, didn't work with chars very much in all these years to be honest.

Thread Thread
 
mellen profile image
Matt Ellen

It only works with lowercase a to z, because UTF-16 represents them as contiguous code points, starting at 97.