JS10 Day 2: Loops

Jmnote (토론 | 기여)님의 2018년 8월 1일 (수) 19:57 판 (→‎개요)

1 개요

Day 2: Loops
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);
    }
}
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]);
    }
}

2 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}