Coder Social home page Coder Social logo

amex-w04d03-map-filter-reduce's Introduction

JavaScript Iterators

.map() link

Write code using .map() to have the following input and output:

  • getSquares – takes in an array of numbers and returns an array of their squares

    • ex: getSquares([1, 2, 3, 4, 5]) => [1, 4, 9, 16, 25]
  • isDivisibleBy3 – takes in an array of numbers and returns an array of booleans indicating whether each element is divisible by 3

    • ex: isDivisibleBy3([1, 3, 4, 6, 7, 8, 9]) => [false, true, false, true, false, false true]

.filter() link

Write code using .filter() to have the following input and output:

  • getOdds – takes in an array of numbers and returns an array of only odd numbers

    • ex: getOdds([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) => [1, 3, 5, 7, 9]
  • getEvens – takes in an array of numbers and returns an array of only even numbers

    • ex: getEvens([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) => [2, 4, 6, 8, 10]
  • getDivisibleBy4 – takes in an array of numbers and returns an array of only numbers that are divisible by 4

    • ex: getDivisibleBy4([1, 4, 6, 8, 12, 13]) => [4, 8, 12]

.reduce() link

Write code using .reduce() to have the following input and output:

  • addUpAll – add up all numbers in a given array

    • ex. addUpAll([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) => 55
  • multiplyAllNums – multiply all numbers in a given array

    • ex. multiplyAllNums([1, 2, 3, 4, 5]) => 120
  • squareAllNums – power up all numbers in a given array

    • ex. squareAllNums([3, 2, 3]) => 729, bc (3 ^ 2) = 9, and (9 ^ 3) = 729
  • addUpAllAges – add up all the ages in an array of objects

    • ex. addUpAllAges([{name: 'Carl', age: 30}, {name: 'Cara', age: 10}, {name: 'Carmen', age: 15}]) => 55

amex-w04d03-map-filter-reduce's People

Contributors

trevorpreston avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.