Header Ad

HackerRank Day 7: Regular Expressions III 10 Days of javascript solution

In this HackerRank Day 7: Regular Expressions III 10 days of javascript problem you need to Complete the function in the editor below by returning a RegExp object, re, that matches every integer in some string s.

HackerRank Day 7: Regular Expressions III 10 Days of javascript solution


HackerRank Day 7: Regular Expressions III 10 Days of javascript problem solution.


'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++];
}

function regexVar() {
    /*
     * Declare a RegExp object variable named 're'
     * It must match ALL occurrences of numbers in a string.
     */
    
    
    /*
     * Do not remove the return statement
     */
    return new RegExp('\\d+', 'g');
}



function main() {
    const re = regexVar();
    const s = readLine();
    
    const r = s.match(re);
    
    for (const e of r) {
        console.log(e);
    }
}


Post a Comment

1 Comments