task/11-katas-2-tasks.js
/**
 * Returns the bank account number parsed from specified string.
 *
 * You work for a bank, which has recently purchased an ingenious machine to assist in reading letters and faxes sent in by branch offices.
 * The machine scans the paper documents, and produces a string with a bank account that looks like this:
 *
 *    _  _     _  _  _  _  _
 *  | _| _||_||_ |_   ||_||_|
 *  ||_  _|  | _||_|  ||_| _|
 *
 * Each string contains an account number written using pipes and underscores.
 * Each account number should have 9 digits, all of which should be in the range 0-9.
 *
 * Your task is to write a function that can take bank account string and parse it into actual account numbers.
 *
 * @param {string} bankAccount
 * @return {number}
 *
 * Example of return :
 *
 *   '    _  _     _  _  _  _  _ \n'+
 *   '  | _| _||_||_ |_   ||_||_|\n'+     =>  123456789
 *   '  ||_  _|  | _||_|  ||_| _|\n'
 *
 *   ' _  _  _  _  _  _  _  _  _ \n'+
 *   '| | _| _|| ||_ |_   ||_||_|\n'+     => 23056789
 *   '|_||_  _||_| _||_|  ||_| _|\n',
 *
 *   ' _  _  _  _  _  _  _  _  _ \n'+
 *   '|_| _| _||_||_ |_ |_||_||_|\n'+     => 823856989
 *   '|_||_  _||_| _||_| _||_| _|\n',
 *
 */
Returns the bank account number parsed from specified string.
You work for a bank, which has recently purchased an ingenious machine to assist in reading letters and faxes sent in by branch offices.
The machine scans the paper documents, and produces a string with a bank account that looks like this.



Each string contains an account number written using pipes and underscores.
Each account number should have 9 digits, all of which should be in the range 0-9.

Your task is to write a function that can take bank account string and parse it into actual account numbers.

@param {string} bankAccount
@return {number}

Example of return .






Returns the bank account number parsed from specified string . You work for a bank which has recently purchased an ingenious machine to assist in reading letters and faxes sent in by branch offices . The machine scans the paper documents and produces a string with a bank account that looks like this . Each string contains an account number written using pipes and underscores . Each account number should have 9 digits all of which should be in the range 0 - 9 . Your task is to write a function that can take bank account string and parse it into actual account numbers . @param { string } bankAccount @return { number } Example of return .
function parseBankAccount(bankAccount) {
      let result='';
    let source=bankAccount.split('\n');
    let pattern=RegExp(/(.{3})/);
    source=source.map(item=>item.split(pattern));
    for(let i=0;i<source[0].length;i++){
        if(source[0][i]==='   '&&source[1][i]==='  |')result+=1;
        if(source[2][i]==='|_ ')result+=2;
        if(source[1][i]===' _|'&&source[2][i]===' _|')result+=3;
        if(source[0][i]==='   '&&source[1][i]==='|_|')result+=4;
        if(source[1][i]==='|_ '&&source[2][i]===' _|')result+=5;
        if(source[1][i]==='|_ '&&source[2][i]==='|_|')result+=6;
        if(source[0][i]===' _ '&&source[2][i]==='  |')result+=7;
        if(source[1][i]==='|_|'&&source[2][i]==='|_|')result+=8;
        if(source[1][i]==='|_|'&&source[2][i]===' _|')result+=9;
        if(source[1][i]==='| |'&&source[2][i]==='|_|')result+=0;
    }
    return result; 
}
function parseBankAccount ( bankAccount ) { let result = '' ; let source = bankAccount . split ( '\n' ) ; let pattern = RegExp ( / (.{3}) / ) ; source = source . map ( item => item . split ( pattern ) ) ; for ( let i = 0 ; i < source [ 0 ] . length ; i ++ ) { if ( source [ 0 ] [ i ] === '   ' && source [ 1 ] [ i ] === '  |' ) result += 1 ; if ( source [ 2 ] [ i ] === '|_ ' ) result += 2 ; if ( source [ 1 ] [ i ] === ' _|' && source [ 2 ] [ i ] === ' _|' ) result += 3 ; if ( source [ 0 ] [ i ] === '   ' && source [ 1 ] [ i ] === '|_|' ) result += 4 ; if ( source [ 1 ] [ i ] === '|_ ' && source [ 2 ] [ i ] === ' _|' ) result += 5 ; if ( source [ 1 ] [ i ] === '|_ ' && source [ 2 ] [ i ] === '|_|' ) result += 6 ; if ( source [ 0 ] [ i ] === ' _ ' && source [ 2 ] [ i ] === '  |' ) result += 7 ; if ( source [ 1 ] [ i ] === '|_|' && source [ 2 ] [ i ] === '|_|' ) result += 8 ; if ( source [ 1 ] [ i ] === '|_|' && source [ 2 ] [ i ] === ' _|' ) result += 9 ; if ( source [ 1 ] [ i ] === '| |' && source [ 2 ] [ i ] === '|_|' ) result += 0 ; } return result ; }
Returns the bank account number parsed from specified string.
Returns the bank account number parsed from specified string .