Skip to content

Commit

Permalink
llipio#77 solutions and test
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinX13 committed Jun 7, 2017
1 parent 8b2beaf commit 3efa11b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
28 changes: 28 additions & 0 deletions solutions/77.js
Original file line number Diff line number Diff line change
@@ -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
};
24 changes: 24 additions & 0 deletions test/77.js
Original file line number Diff line number Diff line change
@@ -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});
});
});

0 comments on commit 3efa11b

Please sign in to comment.