123

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              // ARRAY 1
const texasss = [
  {
    name: 'Mike',
    age: 23,
    gender: 'm',
    us: false,
  },
  {
    name: 'Liz',
    age: 20,
    gender: 'f',
    us: true,
  },
  {
    name: 'Chris',
    age: 102,
    gender: 'm',
    us: true,
  },
  {
    name: 'Chuloo',
    age: 27,
    gender: 'm',
    us: false,
  },
  {
    name: 'Annie',
    age: 30,
    gender: 'f',
    us: true,
  },
]

// Part 1 - Find all users older than 24
const users24 = texasss.filter((val)=>{
  return val.age > 24
})

console.log(users24)


// Part 2 - Find the total age of all users
const totalAge = texasss.map((user)=> user.age).reduce((prev, next)=> prev + next)
console.log(totalAge)


// Part 3 - List all users in the US
const usersUS = texasss.filter(user => {
  return user.us == true;
})

console.log(usersUS)

// ARRAY 2
const newieyork = [
  {
    name: 'Michelle',
    age: 65,
    coder:true,
    gender: 'f',
    us: true,
  },
  {
    name: 'Sam',
    age: 25,
    coder:false,
    gender: 'm',
    us: false,
  },
  {
    name: 'Ivy',
    age: 26,
    coder:true,
    gender: 'f',
    us: false,
  },
  {
    name: 'Nick',
    age: 32,
    coder:true,
    gender: 'm',
    us: true,
  },
  {
    name: 'Jim',
    age: 17,
    coder:false,
    gender: 'm',
    us: true,
  },
]

// Part 1 - List all users in US in ascending order
const sortedUS = newieyork

sortedUS.sort((a, b) => {
  const x = a.name.toLowerCase()
  const y = b.name.toLowerCase()
  return x < y ? -1 : 1 
})

console.log(sortedUS)
    

// Part 2 - Sort all users by age
const sortedAge = newieyork

sortedAge.sort((a, b) => {
  return a.age - b.age
})

console.log(sortedAge)


// Part 3 -  List all female coders
const femaleCoders = newieyork.filter(val=>{
  return val.gender == 'f'
})

console.log(femaleCoders)


// ARRAY 3
const vegzas = [
  {
    name: 'Charly',
    age: 22,
    coder:true,
    gender: 'm',
  },
  {
    name: 'Law',
    age: 21,
    coder:true,
    gender: 'm',
  },
  {
    name: 'Rosey',
    age: 42,
    coder:false,
    gender: 'f',
  },
  {
    name: 'Steph',
    age: 18,
    coder:true,
    gender:'f'
  },
  {
    name: 'Jon',
    age: 47,
    coder:false,
    gender: 'm',
  },
]

// Part 1 - Find the total age of male coders under 25
const maleCodersAge = vegzas
  .filter(val => val.gender == 'm' && val.age < 25)
  .map(male => male.age)
  .reduce((prev, next)=> prev + next)

console.log(maleCodersAge)


// Part 2 - List all male coders over 30
const maleCodersOver30 = vegzas.filter(val => {
  return val.age > 30 && val.gender == 'm'
})

console.log(maleCodersOver30)



// Part 3 - Find the total age of everyone in texasss, newieyork and vegzas combined.
const totalAges = []

texasss.map(val => totalAges.push(val.age))
newieyork.map(val => totalAges.push(val.age))
vegzas.map(val => totalAges.push(val.age))

const ageSum = totalAges.reduce((prev, next)=> prev + next)
console.log(ageSum)
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console