Calculate the word value of any word. Word value is defined as the sum of the values of the characters of any consecutive consonant string.
Steps:
splitCons = str => str.split(/a|e|i|o|u/).filter(subStr => subStr != "")
split()
doesn’t only accept string values but also regular expressions.
A small bug occured when there’s 2 consecutive vowels. In that case you’ll end up with an empty string in your array of strings. Hence the filter()
.
valueLetters = str => str.split("").map(char => char.charCodeAt(0) - 96)
Each character corresponds to a number in the UTF-16. You can use this to convert letters to numbers.
sum = arrNumbers => arrNumbers.reduce((a,b) => a + b)
Summing can be easily done with reduce()
. You provide reduce()
with a function which has an accumulator and a current value as arguments.
You could try to find the highest value with a combination of reduce()
and Math.max()
. However, Math.max()
also accepts rest parameters as shown in the example.
Most solution seem to have followed the split, value and sum pattern. Also most used reduce()
for finding the maximal value but I think Math.max(...)
is nicer.
Is it a good idea to compose these functions in a solve()
function?