SHARE
TWEET

Untitled

a guest Sep 21st, 2017 124 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(args) {
  2.  
  3.     const nN = +args[0];
  4.     let pWp = args.slice(1, nN + 1);
  5.     const mM = +args[nN + 1];
  6.     let pL = args.slice(nN + 2);
  7.     let pricelist = {};
  8.  
  9.     for (let i = 0; i < nN; i += 1) { 
  10.         let element = pWp[i].split(' ');
  11.         let price = parseFloat(element.pop());
  12.         let name = element.join(' ');
  13.         pricelist[name] = price;
  14.  
  15.     }
  16.     for (let i = 0; i < mM; i += 1) { 
  17.         let elementArr = pL[i].split(', ');
  18.         let rowValue = 0;
  19.  
  20.         for (let j = 0; j < elementArr.length; j += 1) {
  21.             let element = elementArr[j].split(' ');
  22.             let count = 1;
  23.             let a = parseFloat(element[0]);
  24.             let name;
  25.  
  26.             if (a >= 0) {
  27.                 count = a;
  28.                 name = element.slice(1).join(' ');
  29.             } else {
  30.                 name = element.join(' ');
  31.             }
  32.             rowValue += count*pricelist[name];
  33.         }
  34.         console.log(rowValue.toFixed(2));
  35.     }
  36.  
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top