Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve (params) {
- params.shift()
- let totalWeight = 0
- let regex = /^n:([^;]+);t:([^;]+);c--([A-Za-z\s]+)$/
- for (let param of params) {
- let match = param.match(regex)
- if (match) {
- let [name, kind, country] = [match[1], match[2], match[3]]
- let weight = 0
- weight += name
- .split('')
- .filter(x => x.match(/\d+/))
- .map(Number)
- .reduce((a, b) => a + b, 0)
- weight += kind
- .split('')
- .filter(x => x.match(/\d+/))
- .map(Number)
- .reduce((a, b) => a + b, 0)
- name = name
- .split('')
- .filter(x => x.match(/[A-Za-z\s]/))
- .join('')
- kind = kind
- .split('')
- .filter(x => x.match(/[A-Za-z\s]/))
- .join('')
- country = country
- .split('')
- .filter(x => x.match(/[A-Za-z\s]/))
- .join('')
- console.log(`${name} is a ${kind} from ${country}`)
- totalWeight += weight
- }
- }
- console.log(`Total weight of animals: ${totalWeight}KG`)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement