-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathcountLetter.js
35 lines (31 loc) · 1.06 KB
/
countLetter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* Given an input string and a target letter, returns the number of times
* the target letter appears in the string.
*
* Note:
* 1. You can use a `for...of` loop to iterate through the characters
* of a string one letter at a time.
* 2. You can access a specific character using string[i], as
* if the string were an array.
*
* Both of these are enough to complete this exercise.
*
* @example
* countLetter('hello', 'l'); // => 2
* countLetter('Mississippi', 's'); // => 4
* countLetter('Mississippi', 'x'); // => 0
* countLetter('Mississippi', 'm'); // => 0 (no lower-case m's)
*
* @param {string} string - The string to search
* @param {string} letter - The target letter
* @returns {string} The number of times target letter appears in input string
*/
function countLetter(string, letter) {
// This is your job. :)
}
if (require.main === module) {
console.log('Running sanity checks for countLetter:');
// Add your own sanity checks here.
// How else will you be sure your code does what you think it does?
}
module.exports = countLetter;