Coder Social home page Coder Social logo

js-exercises's Introduction

Introduction

Our goal with these exercises is to use arrays, objects, and the fundamental building blocks of JS to query our data and make new assertions. From a list of people whose attributes we have, what conclusions can be drawn?

  1. The data we will work with on each exercise is the people array.
  2. Take a moment to think about the objects in the array.
  3. Contemplate how we could sort people based on the data we have about them.
  4. All functions we write in this exercise will take the people array as it's only argument

In the commented example below, we use the old javascript syntax to define the function getAmericans().

Although this works, we should prefer to use the new ES6 syntax.

ES5(Old Javascript)

function getAmericans(persons) {
  // ... code ...
}

ES6(New Javascript)

const getAmericans = (persons) => {
  // ... code ...
}

What's different between the two definitionds?

  • Notice that the 'function' keyword is replaced by const. Also, there is a equal = between the function name and argument(s).

  • Notice also how the parentheses can be left out if the function takes exactly one argument(line 161 & 168 are exactly the same).

  • Lastly, notice how the argument is proceeded by a fat arrow => and then the opening curly brace for the beginning of the function body

const getAmericans = (persons) => {
  // ... code ...
}

View map's element with this code snippet

(() =>
  setTimeout(() => {
    console.log("%cIndex of people array: ", "color: green", idx);
    console.log(`%cElement: `, "color: green", person);
  }, 3000 * idx))(idx);

js-exercises's People

Contributors

primetimetran avatar haichungcn avatar

Watchers

James Cloos avatar  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.