Advertisement
Guest User

SecondSoluition

a guest
Apr 4th, 2020
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function secondSolution(num) {
  2.     const isNumeric = (leftInteger) => /^[0-9]*$/.test(leftInteger);
  3.  
  4.     if (isNumeric(num) === false) {
  5.         throw 'Invaid Argument!';
  6.     }
  7.  
  8.     const format = {
  9.         under: ['', '일', '이', '삼', '사', '오', '육', '칠', '팔', '구'],
  10.         overTenUnderThousend: ['', '십', '백', '천', ],
  11.         overThousendUnderTrillion: ['', '만', '억', '조'],
  12.     };
  13.  
  14.     let rlt = [];
  15.     let splitStrByLen = String(num).split('').reverse()
  16.         .join('')
  17.         .match(/.{1,4}/g);
  18.     let rltIdx = 0;
  19.     splitStrByLen.forEach((v, i) => {
  20.         let formatIdx = 0;
  21.         v.split('').forEach((splitValue, splitIdx) => {
  22.             if (typeof (format.under[splitValue]) == 'undefined' || format.under[splitValue]) {
  23.                 rlt[rltIdx] = `${format.under[splitValue]}${format.overTenUnderThousend[splitIdx]}`;
  24.                 if (formatIdx === 0) {
  25.                     rlt[rltIdx] = `${rlt[rltIdx]}${format.overThousendUnderTrillion[i]}`;
  26.                 }
  27.                 formatIdx++;
  28.             }
  29.             rltIdx++;
  30.         });
  31.     });
  32.     return rlt.reverse().join('');
  33. }
  34.  
  35.  
  36. const readline = require("readline");
  37. const rl = readline.createInterface({
  38.     input: process.stdin,
  39.     output: process.stdout
  40. });
  41.  
  42. rl.on("line", function (line) {
  43.     console.log(secondSolution(String(line)));
  44.     rl.close();
  45. }).on("close", function () {
  46.     process.exit();
  47. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement