GithubHelp home page GithubHelp logo

jrhorn424 / js-array-methods Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ga-wdi-boston/js-array-iteration-methods

0.0 1.0 0.0 17 KB

JavaScript Array methods

License: Other

JavaScript 100.00%

js-array-methods's Introduction

General Assembly Logo

JavaScript Array methods

Prerequisites

Introduction

We'll look at the array methods that allow us to test and transform arrays more simply and consistently.

Objectives

By the end of this lesson, students should be able to:

  • Write callbacks to pass to array methods
  • Write functions to emulate array methods
  • Write functions using array methods to add functionality.

Array Methods

We'll explore and implement proxies for a variety of the JavaScript Array methods.

Array

Callbacks

A callback is a function that gets passed into an initial function/method as an argument, so that the initial function/method can invoke it.

Arrow Functions

We'll also be working with arrow (sometimes referred to as fat arrow) functions versus standard function declarations.

Arrow functions:

  • always have a bound this
  • cannot be used as a Constructor (no new, no prototypes)
  • no arguments
> typeof () => {}
'function'

> () => {} instanceof Function
true

Demo

forEach

  • The forEach method iterates over all of the elements in an array.
  • Unlike a for loop, forEach cannot be stopped or broken out of
  • Does not change the elements of the original array and will return undefined

Code along

map

  • The map method returns a new array with the results of the functions applied to the array it is called upon
  • The array it is called upon therefore is not mutated

Lab

Write a function, mutate, that takes an array and a function as arguments and *does change the original array based on the return value of invoking transform.

const mutate = function(array, transform) {

};

Demo

reduce

  • The reduce method returns a single value from operating on all the values in the array. It "reduces" many to one.
  • The original array reduce is invoked on does not change.

Code along

every

  • The every method checks to see if all elements of an array meet some test. The function used for this should only return true or false. This type of function is often called a predicate.

Further Practice

Research the some and filter methods as they are also useful.

  • What is the purpose of each?
  • What is returned from each?
  • Is the array they are called upon mutated?

Source code distributed under the MIT license. Text and other assets copyright General Assembly, Inc., all rights reserved.

js-array-methods's People

Contributors

laurenfazah avatar

Watchers

 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.