forked from llipio/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); | ||
}); | ||
}); |