-
Notifications
You must be signed in to change notification settings - Fork 287
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
Justine Philip
committed
Jan 8, 2019
0 parents
commit bffec76
Showing
5 changed files
with
5,543 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 @@ | ||
node_modules |
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,25 @@ | ||
/* | ||
An iterative approach to counting the number of vowels in a | ||
string of text. | ||
*/ | ||
|
||
const vowels = ["a", "e", "i", "o", "u"] | ||
|
||
function vowelsCounter(text) { | ||
// Initialize counter | ||
let counter = 0; | ||
|
||
|
||
// Loop through text to test if each character is a vowel | ||
for (let letter of text.toLowerCase()){ | ||
if (vowels.includes(letter)) { | ||
counter++ | ||
} | ||
} | ||
|
||
// Return number of vowels | ||
return counter | ||
} | ||
|
||
|
||
module.exports = vowelsCounter; |
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,13 @@ | ||
const vowelsCounter = require('./index'); | ||
|
||
test('vowelsCounter is a function', () => { | ||
expect(typeof vowelsCounter).toEqual('function'); | ||
}); | ||
|
||
test('returns the number of vowels found', () => { | ||
expect(vowelsCounter('aeiou')).toEqual(5); | ||
}); | ||
|
||
test('returns the number of vowels found when string is capitalized', () => { | ||
expect(vowelsCounter('AEIOU')).toEqual(5); | ||
}); |
Oops, something went wrong.