Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- animal = (arr) => {
- let count = arr.shift();
- let weightArr = [];
- arr.forEach(element => {
- const patternName = new RegExp ("^n:[€£ -~]+$")
- const patternType = new RegExp ("^t:[€£ -~]+$", "gi")
- const patternCountry = new RegExp("^c--[ a-z]+$","gi")
- let [name, type, country] = element.split(';')
- if(name.match(patternName) != null&& type.match(patternType) !== null && country.match(patternCountry) != null){
- element.split('').forEach(x => {
- if (!isNaN(x)){
- weightArr.push(x)
- }
- })
- name = name.split('').map(x => {
- if(x.match(new RegExp("[a-z ]","i"))){
- return x;
- }
- })
- type = type.split('').map(x => {
- if(x.match(new RegExp("[a-z ]","i"))){
- return x;
- }
- })
- country = country.split('').map(x => {
- if(x.match(new RegExp("[a-z ]","i"))){
- return x;
- }
- })
- name.shift()
- type.shift()
- country.shift()
- console.log(`${name.join('')} is a ${type.join('')} from ${country.join('')}`)
- }
- }
- );
- let sum =0
- weightArr.forEach(element => {
- sum+=Number(element)
- });
- console.log(`Total weight of animals: ${sum}KG`)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement