SHARE
TWEET

Untitled

nikolayneykov Apr 22nd, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve (params) {
  2.   params.shift()
  3.   let totalWeight = 0
  4.   let regex = /^n:([^;]+);t:([^;]+);c--([A-Za-z\s]+)$/
  5.  
  6.   for (let param of params) {
  7.     let match = param.match(regex)
  8.  
  9.     if (match) {
  10.       let [name, kind, country] = [match[1], match[2], match[3]]
  11.  
  12.       let weight = 0
  13.       weight += name
  14.         .split('')
  15.         .filter(x => x.match(/\d+/))
  16.         .map(Number)
  17.         .reduce((a, b) => a + b, 0)
  18.  
  19.       weight += kind
  20.         .split('')
  21.         .filter(x => x.match(/\d+/))
  22.         .map(Number)
  23.         .reduce((a, b) => a + b, 0)
  24.  
  25.       name = name
  26.         .split('')
  27.         .filter(x => x.match(/[A-Za-z\s]/))
  28.         .join('')
  29.       kind = kind
  30.         .split('')
  31.         .filter(x => x.match(/[A-Za-z\s]/))
  32.         .join('')
  33.       country = country
  34.         .split('')
  35.         .filter(x => x.match(/[A-Za-z\s]/))
  36.         .join('')
  37.  
  38.       console.log(`${name} is a ${kind} from ${country}`)
  39.       totalWeight += weight
  40.     }
  41.   }
  42.  
  43.   console.log(`Total weight of animals: ${totalWeight}KG`)
  44. }
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