
This is a Ruby function
def new_count(word)
word.downcase!
return 1 if word.length <= 3
word.sub!(/(?:[^laeiouy]es|ed|[^laeiouy]e)$/, '')
word.sub!(/^y/, '')
word.scan(/[aeiouy]{1,2}/).size
end
This is an equivalent function in JavaScript.
function newCount(word) {
word = word.toLowerCase();
if (word.length <= 3) return 1;
word = word.replace(/(?:[^laeiouy]es|ed|[^laeiouy]e)$/, '');
word = word.replace(/^y/, '');
return word.match(/[aeiouy]{1,2}/g).length;
}
The above is the detailed content of A Ruby/JS Equivalence. For more information, please follow other related articles on the PHP Chinese website!
What is the difference between guid and mbr formats
app full name
vcruntime140.dll cannot be found and code execution cannot continue
What should I do if the print spooler cannot be started?
What are the java workflow engines?
The difference between typedef and define
The difference between wildcard masking and unmasking
The meaning of European and American website construction