From c3bb55f1077387cf0d01e72763d20dbd59532963 Mon Sep 17 00:00:00 2001 From: seemcat Date: Mon, 12 Jun 2017 14:29:51 -0700 Subject: [PATCH 1/2] Another test & solution for #77 --- solutions/77.js | 15 ++++++++++++++- test/77.js | 4 ++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/solutions/77.js b/solutions/77.js index d93f760..bcb3ebc 100644 --- a/solutions/77.js +++ b/solutions/77.js @@ -18,4 +18,17 @@ const solution = (string) =>{ return data; }; -module.exports = {solution}; +const solution1 = (string) =>{ + let i = 0; + let obj = {}; + while (i < string.length){ + if (string[i] === 'a' || 'e' || 'i' || 'o' || 'u'){ + obj.vowel =+ 1; + } + obj.consonant =+ 1; + } + console.log('obj', obj); + return obj; +}; + +module.exports = {solution, solution1}; diff --git a/test/77.js b/test/77.js index 9f924bf..a905f69 100644 --- a/test/77.js +++ b/test/77.js @@ -1,8 +1,12 @@ 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: 2, consonant: 4 } for "yellow"', () =>{ + expect(solution1('yellow')).to.eql({vowel: 2, consonant: 4 }); + }); }); From 2dbda689b1c68986c6397165e502aac24d81116e Mon Sep 17 00:00:00 2001 From: seemcat Date: Thu, 22 Jun 2017 09:56:25 -0700 Subject: [PATCH 2/2] CORRECT SOLUTION! --- solutions/77.js | 13 +++++++++---- test/77.js | 9 ++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/solutions/77.js b/solutions/77.js index bcb3ebc..91f5ff8 100644 --- a/solutions/77.js +++ b/solutions/77.js @@ -20,14 +20,19 @@ const solution = (string) =>{ const solution1 = (string) =>{ let i = 0; + let j = 0; + let k = 0; let obj = {}; while (i < string.length){ - if (string[i] === 'a' || 'e' || 'i' || 'o' || 'u'){ - obj.vowel =+ 1; + 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; } - obj.consonant =+ 1; + i++; } - console.log('obj', obj); return obj; }; diff --git a/test/77.js b/test/77.js index a905f69..39d8a96 100644 --- a/test/77.js +++ b/test/77.js @@ -6,7 +6,14 @@ 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: 2, consonant: 4 } for "yellow"', () =>{ + 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 }); + }); + });