JS10 Day 2: Loops

개요[ | ]

Day 2: Loops
해커랭크 10 Days of Javascript
# 문제 비고
2-3 Day e
6 JS10 Day 2: Conditional Statements: If-Else
7 JS10 Day 2: Conditional Statements: Switch
8 JS10 Day 2: Loops
9 JS10 Day 3: Arrays
10 JS10 Day 3: Try, Catch, and Finally
11 JS10 Day 3: Throw

상단
'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++];
}
구현예시 1
function isVowel(ch) {
    if( ch == 'a' ) return true;
    if( ch == 'e' ) return true;
    if( ch == 'i' ) return true;
    if( ch == 'o' ) return true;
    if( ch == 'u' ) return true;
    return false;
}
function vowelsAndConsonants(s) {
    for( let i=0; i<s.length; i++ ) {
        let ch = s[i];
        if( isVowel(ch) ) console.log(ch);
    }
    for( let i=0; i<s.length; i++ ) {
        let ch = s[i];
        if( !isVowel(ch) ) console.log(ch);
    }
}
구현예시 2
function vowelsAndConsonants(s) {
    var vowels = ['a','e','i','o','u'];
    for( let i=0; i<s.length; i++ ) {
        if( vowels.indexOf(s[i]) > -1 ) console.log(s[i]);
    }
    for( let i=0; i<s.length; i++ ) {
        if( vowels.indexOf(s[i]) < 0 ) console.log(s[i]);
    }
}
하단
function main() {
    const s = readLine();
    
    vowelsAndConsonants(s);
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}