Skip to content

Instantly share code, notes, and snippets.

@thuyanduong
Last active November 16, 2020 13:53
Show Gist options
  • Save thuyanduong/c7f044d00d76925b61ab46665e54bf48 to your computer and use it in GitHub Desktop.
Save thuyanduong/c7f044d00d76925b61ab46665e54bf48 to your computer and use it in GitHub Desktop.
Tech Discussion
  1. Write a function that takes an array of characters and returns an array of just the character names (as strings) that are superheroes:
    const characters = [
      { character: 'Superman', hero: true },
      { character: 'Sinestro', hero: false },
      { character: 'Wonder Woman', hero: true },
      { character: 'Lex Luthor', hero: false },
      { character: 'Green Lantern', hero: true }
    ]
    
    const heroNames = function(chars) {
      // your code here
    }; 
    
    heroNames(characters)  // => ['Superman', 'Wonder Woman', 'Green Lantern']
  2. Write a function that takes an array of arrays that contain product information, and returns an array of objects with appropriate keys:
    const products =  [
      ['Dark Chocolate Crunchies', 4.11, 3],
      ['Peppermint Poppers', 0.88, 1],
      ['Banana Bunches', 2.33, 2]
    ]
    
    const toObject = function(products) {
      // your code here
    };
    
    toObject(products); // => [
    //   { name: 'Dark Chocolate Crunchies', price: 4.11, quantity: 3 },
    //   { name: 'Peppermint Poppers', price: 0.88, quantity: 1 },
    //   { name: 'Banana Bunches', price: 2.33, quantity: 2 }
    // ] 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment