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)
- }
- })
- const letters = (word =>{
- let result = [];
- word.split('').map(x => {
- if(x.match(new RegExp("[a-z ]","i"))){
- result.push(x)
- }
- })
- result.shift()
- return result.join('')
- })
- name = letters(name)
- type = letters(type)
- country = letters(country)
- console.log(`${name} is a ${type} from ${country}`)
- }
- }
- );
- 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