diff --git a/solutions/77.js b/solutions/77.js index d93f760..91f5ff8 100644 --- a/solutions/77.js +++ b/solutions/77.js @@ -18,4 +18,22 @@ const solution = (string) =>{ return data; }; -module.exports = {solution}; +const solution1 = (string) =>{ + let i = 0; + let j = 0; + let k = 0; + let obj = {}; + while (i < string.length){ + if (string[i] == 'a' || string[i] =='e' || string[i] =='i' || string[i] =='o' || string[i] =='u'){ + j++; + obj.vowel = j; + } else { + k++; + obj.consonant = k; + } + i++; + } + return obj; +}; + +module.exports = {solution, solution1}; diff --git a/test/77.js b/test/77.js index 9f924bf..39d8a96 100644 --- a/test/77.js +++ b/test/77.js @@ -1,8 +1,19 @@ const expect = require('chai').expect; let solution = require('../solutions/77').solution; +let solution1 = require('../solutions/77').solution1; describe('Return the count of vowels and consonants', () =>{ it('should return { vowel: 2, consonant: 4 } for "yellow"', () =>{ expect(solution('yellow')).to.eql({vowel: 2, consonant: 4 }); }); + it('should return { vowel: 3, consonant: 5 } for "maricris"', () =>{ + expect(solution1('yellow')).to.eql({vowel: 2, consonant: 4 }); + }); + it('should return { vowel: 3, consonant: 4 } for "goodbye"', () =>{ + expect(solution1('goodbye')).to.eql({vowel: 3, consonant: 4 }); + }); + it('should return { vowel: 2, consonant: 3 } for "bonzo"', () =>{ + expect(solution1('bonzo')).to.eql({vowel: 2, consonant: 3 }); + }); + });