Skip to content

Commit 61c0057

Browse files
Merge pull request #18 from wakidurrahman/feat/write-function-returns-number-of-vowels-in-string
feat(write-function-returns-number-of-vowels-in-string): implement vowel
2 parents 0df7d9b + 1f63910 commit 61c0057

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Write a function that returns the number of vowels in a string.
3+
*
4+
* Another common interview question: Write a function that returns the number of vowels in a string.
5+
* Here we have two solutions,
6+
* one makes use of a regular expression, and
7+
* another uses an iterative approach, a for-of loop.
8+
*
9+
* Used in a string. Vowels are the characters "a", "e", "i", "o" and "u"
10+
*/
11+
// Solution 1: using regular expression
12+
// function vowelsHandleByReg(characters: string) {
13+
// const matches = characters.match(/[aeiou]/gi);
14+
// return matches ? matches.length : 0;
15+
// }
16+
// Solution 2: uses an iterative approach, a for-of loop.
17+
function vowelsHandleByIterative(characters) {
18+
var count = 0;
19+
var checker = ["a", "e", "i", "0", "u"];
20+
for (var _i = 0, _a = characters.toLowerCase(); _i < _a.length; _i++) {
21+
var char = _a[_i];
22+
if (checker.includes(char)) {
23+
count++;
24+
}
25+
}
26+
return count;
27+
}
28+
// console.log(vowelsHandleByReg("Wakidur"));
29+
console.log(vowelsHandleByIterative("Munni"));
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Write a function that returns the number of vowels in a string.
3+
*
4+
* Another common interview question: Write a function that returns the number of vowels in a string.
5+
* Here we have two solutions,
6+
* one makes use of a regular expression, and
7+
* another uses an iterative approach, a for-of loop.
8+
*
9+
* Used in a string. Vowels are the characters "a", "e", "i", "o" and "u"
10+
*/
11+
12+
// Solution 1: using regular expression
13+
14+
// function vowelsHandleByReg(characters: string) {
15+
// const matches = characters.match(/[aeiou]/gi);
16+
// return matches ? matches.length : 0;
17+
// }
18+
19+
// Solution 2: uses an iterative approach, a for-of loop.
20+
function vowelsHandleByIterative(characters: string) {
21+
let count: number = 0;
22+
const checker: string[] = ["a", "e", "i", "0", "u"];
23+
24+
for (let char of characters.toLowerCase()) {
25+
if (checker.includes(char)) {
26+
count++;
27+
}
28+
}
29+
return count;
30+
}
31+
32+
33+
// console.log(vowelsHandleByReg("Wakidur"));
34+
console.log(vowelsHandleByIterative("Munni"));

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
1212

1313
/* Language and Environment */
14-
"target": "es5", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
15-
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
14+
"target": "es6", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
15+
"lib": ["es2016.Array.Include", "es2016", "es6"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
1616
// "jsx": "preserve", /* Specify what JSX code is generated. */
1717
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
1818
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */

0 commit comments

Comments
 (0)