diff --git a/solutions/77.js b/solutions/77.js new file mode 100644 index 0000000..e593e9c --- /dev/null +++ b/solutions/77.js @@ -0,0 +1,28 @@ +// Take a string, returns an object that shows how many vowels and consonants are in the string + +// Input: "head" +// Output: +// {vowel: 2 +// consonant:3 +// } + +// Solutions by Colin Xie @ColinX13 +/** +* @param {string} string - the string Input +* @param {object{}} letterObj - the object containing the number of consonants and vowels +*/ +const solution = (string) => { + let letterObj = {'vowel': 0, + 'consonant': 0}; + for(let i = 0; i < string.length; i++){ + if(string[i] === 'a' || string[i] === 'e' || string[i] === 'i' || string[i] === 'o' || string[i] === 'u'){ + letterObj['vowel'] = letterObj['vowel'] + 1; + }else{ + letterObj['consonant'] = letterObj['consonant'] + 1 + } + } + return letterObj; +}; +module.exports = { + solution +}; diff --git a/test/77.js b/test/77.js new file mode 100644 index 0000000..098765b --- /dev/null +++ b/test/77.js @@ -0,0 +1,24 @@ +const expect = require('chai').expect; +let solution = require('../solutions/77').solution; +// solution = require('./yourSolution').solution; + +describe('vowel and consonant', () => { + it('by has 0 vowel and 2 consonant', () => { + expect(solution('by')).eql({'vowel': 0, 'consonant': 2}); + }); + it('head has 2 vowels and 2 consonants', () => { + expect(solution('head')).eql({'vowel': 2, 'consonant': 2}); + }); + it('jacques has 3 vowels and 4 consonants', () => { + expect(solution('jacques')).eql({'vowel': 3, 'consonant':4}); + }); + it('everything has 3 vowels and 7 consonants', () => { + expect(solution('everything')).eql({'vowel': 3, 'consonant': 7}); + }); +it('titans has 2 vowel and 4 consonant', () => { + expect(solution('titans')).eql({'vowel': 2, 'consonant': 4}); + }); +it('silence has 3 vowel and 4 consonant', () => { + expect(solution('silence')).eql({'vowel': 3, 'consonant': 4}); + }); +});