[JAVASCRIPT][HackerRank]10 days of JS Day2
in Algorithm
Day 2-1. arithmetic operators(산술연산자)
'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
inputString += inputStdin;
});
process.stdin.on('end', _ => {
inputString = inputString.trim().split('\n').map(string => {
return string.trim();
});
main();
});
function readLine() {
return inputString[currentLine++];
}
/**
* Calculate the area of a rectangle.
*
* length: The length of the rectangle.
* width: The width of the rectangle.
*
* Return a number denoting the rectangle's area.
**/
function getArea(length, width) {
let area;
// Write your code here
area = length * width;
return area;
}
/**
* Calculate the perimeter of a rectangle.
*
* length: The length of the rectangle.
* width: The width of the rectangle.
*
* Return a number denoting the perimeter of a rectangle.
**/
function getPerimeter(length, width) {
let perimeter;
// Write your code here
perimeter = 2 * (length + width);
return perimeter;
}
Day2-2. loops
First, print each vowel in on a new line (in the same order as they appeared in ). Second, print each consonant (i.e., non-vowel) in on a new line (in the same order as they appeared in ).
sample output
javascriptloops
sample output
a
a
i
o
o
j
v
s
c
r
p
t
l
p
s
'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
inputString += inputStdin;
});
process.stdin.on('end', _ => {
inputString = inputString.trim().split('\n').map(string => {
return string.trim();
});
main();
});
function readLine() {
return inputString[currentLine++];
}
/*
* Complete the vowelsAndConsonants function.
* Print your output using 'console.log()'.
*/
function vowelsAndConsonants(s) {
const vowel = ['a','e','i','o','u'];
for(let i=0; i<s.length; i++){
if(s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i]== 'u'){
console.log(s[i]);
}
}
for(let i=0; i<s.length; i++){
if(s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i]== 'u'){
}else{
console.log(s[i]);
}
}
}
Day 2-3. function
'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
inputString += inputStdin;
});
process.stdin.on('end', _ => {
inputString = inputString.trim().split('\n').map(string => {
return string.trim();
});
main();
});
function readLine() {
return inputString[currentLine++];
}
/*
* Create the function factorial here
*/
function factorial(n){
if(n === 0){
return 1;
} else{
return n * factorial(n-1);
}
}
function main() {
const n = +(readLine());
console.log(factorial(n));
}