Skip to content

Instantly share code, notes, and snippets.

@naxmefy
Created October 31, 2020 23:21
Show Gist options
  • Save naxmefy/af18829eea20a328dae6882d735660ac to your computer and use it in GitHub Desktop.
Save naxmefy/af18829eea20a328dae6882d735660ac to your computer and use it in GitHub Desktop.
/**
* @param {string} s the sentence
* @returns {number} amount of double letter words in the given sentence
*/
function doubleLetterWords(s) {
return s.split(' ').map(w => w.match(/(.)\1/m)?1:0).reduce((a,b)=>a+b)
}
// e.g
// doubleLetterWords("letter cool all rofl") => 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment