Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function animalSanctuary(input) {
- let totalWeight = 0;
- for (let line of input.slice(1)) {
- let regex = /^n:(?<name>[^;]+);t:(?<kind>[^;]+);c--(?<country>[A-Za-z ]+)$/g;
- let match = regex.exec(line);
- if (match !== null) {
- let weight = line.match(/[\d]/g);
- let { name, kind, country } = match.groups;
- let animalName = name.match(/[A-Za-z ]*/g);
- let animalKind = kind.match(/[A-Za-z ]*/g);
- if (animalName !== null && animalKind !== null && country !== null) {
- if (weight !== null) {
- weight = weight.map(Number).reduce((a, b) => a + b, 0);
- totalWeight += weight;
- }
- console.log(`${animalName.join('')} is a ${animalKind.join('')} from ${country}`);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement