Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript create a function that counts the number of syllables a word has. each syllable is separated with a dash -.

function new_count(word) {
  word = word.toLowerCase();                                     //word.downcase!
  if(word.length <= 3) { return 1; }                             //return 1 if word.length <= 3
    word = word.replace(/(?:[^laeiouy]es|ed|[^laeiouy]e)$/, '');   //word.sub!(/(?:[^laeiouy]es|ed|[^laeiouy]e)$/, '')
    word = word.replace(/^y/, '');                                 //word.sub!(/^y/, '')
    return word.match(/[aeiouy]{1,2}/g).length;                    //word.scan(/[aeiouy]{1,2}/).size
}

console.log(new_count('she'));
console.log(new_count('spain'))
console.log(new_count('softball'))
console.log(new_count('contagion'))
Comment

PREVIOUS NEXT
Code Example
Javascript :: get all div elements javascript 
Javascript :: javascript object array iteration 
Javascript :: nodemailer custom font 
Javascript :: js minifier api 
Javascript :: remove trailing slash javascript 
Javascript :: javascript object entries 
Javascript :: variable key name js 
Javascript :: discord.js how to use subcommands 
Javascript :: localstorage javascript 
Javascript :: moment add 6 months 
Javascript :: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory 
Javascript :: how to check what browser you are using javascript 
Javascript :: padend method in javascript 
Javascript :: javascript switch statement multiple cases 
Javascript :: javascript multiples of 3 and 5 
Javascript :: javascript trim spaces 
Javascript :: check if array has same values javascript 
Javascript :: Convert a string to a number in jQuery 
Javascript :: infinite loop javascript 
Javascript :: array methods javascript 
Javascript :: react native check os 
Javascript :: how to divide equal 3 parts of an array javascript 
Javascript :: difference between type and method in ajax 
Javascript :: sort array based on another array 
Javascript :: react date picker disable past dates 
Javascript :: flatlist react native 
Javascript :: date split in javascript 
Javascript :: find in array react 
Javascript :: run function every second javascript 
Javascript :: jQuery CSS Classes 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =