Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another test & solution for #77 #100

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion solutions/77.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,22 @@ const solution = (string) =>{
return data;
};

module.exports = {solution};
const solution1 = (string) =>{
let i = 0;
let j = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a working solution. Good start! Now try to implement this solution without using extra variables j and k. Hint: initialize obj before entering the while loop.

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};
11 changes: 11 additions & 0 deletions test/77.js
Original file line number Diff line number Diff line change
@@ -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"', () =>{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we replace this test case with a different scenario - like a word without 0 vowel or 0 constant?

expect(solution1('bonzo')).to.eql({vowel: 2, consonant: 3 });
});

});