This content originally appeared on DEV Community and was authored by Innovation Leadership
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;
}
This content originally appeared on DEV Community and was authored by Innovation Leadership
Print
Share
Comment
Cite
Upload
Translate
Updates
There are no updates yet.
Click the Upload button above to add an update.
APA
MLA
Innovation Leadership | Sciencx (2024-08-24T02:17:40+00:00) A Ruby/JS Equivalence. Retrieved from https://www.scien.cx/2024/08/24/a-ruby-js-equivalence/
" » A Ruby/JS Equivalence." Innovation Leadership | Sciencx - Saturday August 24, 2024, https://www.scien.cx/2024/08/24/a-ruby-js-equivalence/
HARVARDInnovation Leadership | Sciencx Saturday August 24, 2024 » A Ruby/JS Equivalence., viewed ,<https://www.scien.cx/2024/08/24/a-ruby-js-equivalence/>
VANCOUVERInnovation Leadership | Sciencx - » A Ruby/JS Equivalence. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/08/24/a-ruby-js-equivalence/
CHICAGO" » A Ruby/JS Equivalence." Innovation Leadership | Sciencx - Accessed . https://www.scien.cx/2024/08/24/a-ruby-js-equivalence/
IEEE" » A Ruby/JS Equivalence." Innovation Leadership | Sciencx [Online]. Available: https://www.scien.cx/2024/08/24/a-ruby-js-equivalence/. [Accessed: ]
rf:citation » A Ruby/JS Equivalence | Innovation Leadership | Sciencx | https://www.scien.cx/2024/08/24/a-ruby-js-equivalence/ |
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.