chaesthetics / FrontEnd-Dev

For Meta Certification
0 stars 0 forks source link

Data Structure #36

Open chaesthetics opened 11 months ago

chaesthetics commented 11 months ago
const fruits = ['kiwi','mango','apple','pear'];
function appendIndex(fruit, index) {
    console.log(`${index}. ${fruit}`)
}
fruits.forEach(appendIndex);
  1. kiwi
  2. mango
  3. apple
  4. pear
chaesthetics commented 11 months ago
const veggies = ['onion', 'garlic', 'potato'];
veggies.forEach( function(veggie, index) {
    console.log(`${index}. ${veggie}`);
});
chaesthetics commented 11 months ago
const nums = [0,10,20,30,40,50];
nums.filter( function(num) {
    return num > 20;
})

[30,40,50]

chaesthetics commented 11 months ago
[0,10,20,30,40,50].map( function(num) {
    return num / 10
})

[0,1,2,3,4,5]

chaesthetics commented 11 months ago
const result = [];
const drone = {
    speed: 100,
    color: 'yellow'
}
const droneKeys = Object.keys(drone);
droneKeys.forEach( function(key) {
    result.push(key, drone[key])
})
console.log(result)

['speed',100,'color','yellow']