관리 메뉴

Silver Library (Archived)

Loops - JS algorithm 본문

F2. Problem & Solving/Solving

Loops - JS algorithm

Ayin Kim 2021. 6. 12. 23:23
반응형

https://www.hackerrank.com/challenges/js10-loops/problem

 

Personal note:

the code makes sense but how on earth I can remember such a method on that day...?

whatever the condition is; I need to keep rolling this.

 

'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) { // from now on, vowelsAndConsonants = s

    const vowels = 'aeiou'; // 

    var consonants = ''; // leave it blank to receive/add new value from i++ accordingly?

    

    for(let i=0; i < s.length; i++) {

        if (vowels.includes(s[i])) {

            console.log(s[i]);

        }

        else {

            consonants += s[i] + '\n';

        } 

    }

    console.log(consonants.trim());

}



function main() {

    const s = readLine();

    

    vowelsAndConsonants(s);

}

'F2. Problem & Solving > Solving' 카테고리의 다른 글

[Node.js] - what is readline() modul?  (0) 2021.07.06
[JS] string includes() method  (0) 2021.07.06
Conditional statements: switch  (0) 2021.06.12
Conditional statement: if-else  (0) 2021.06.12
[JS] Day 1 : let and const  (0) 2021.06.11