Skip to content

Commit a181173

Browse files
authored
Create Loops.js
1 parent 8b4863a commit a181173

File tree

1 file changed

+54
-0
lines changed
  • Hackerrank solutions/10 days of js

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
'use strict';
2+
3+
process.stdin.resume();
4+
process.stdin.setEncoding('utf-8');
5+
6+
let inputString = '';
7+
let currentLine = 0;
8+
9+
process.stdin.on('data', inputStdin => {
10+
inputString += inputStdin;
11+
});
12+
13+
process.stdin.on('end', _ => {
14+
inputString = inputString.trim().split('\n').map(string => {
15+
return string.trim();
16+
});
17+
18+
main();
19+
});
20+
21+
function readLine() {
22+
return inputString[currentLine++];
23+
}
24+
25+
/*
26+
* Complete the vowelsAndConsonants function.
27+
* Print your output using 'console.log()'.
28+
*/
29+
function vowelsAndConsonants(s) {
30+
//for vowels
31+
for(let ind=0; ind<s.length; ind++){
32+
if(s.charAt(ind).match(/[aeiou]/)){
33+
console.log(s.charAt(ind));
34+
}
35+
}
36+
//for consonants
37+
38+
for(let ind=0; ind<s.length; ind++){
39+
if(s.charAt(ind).match(/[^aeiou]/)){
40+
console.log(s.charAt(ind));
41+
}
42+
}
43+
}
44+
45+
46+
47+
48+
49+
50+
function main() {
51+
const s = readLine();
52+
53+
vowelsAndConsonants(s);
54+
}

0 commit comments

Comments
 (0)