Giter VIP home page Giter VIP logo

array-method-drills's Introduction

Array Method Drills

Getting started

  1. Fork and clone this repository.

  2. Navigate to the cloned repository's directory on your command line. Then, run the following command:

    npm install
    

    This will install the libraries needed to run the tests.

  3. Open up the repository in VSCode. Follow the instructions below to complete the Lab.

Tests

To run the tests, you can run the following command from the command line. You will need to be in the root directory of your local directory.

npm test

This will run the test output once.

Two arrays to work with

const nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0];

const panagram = [
  "The",
  "quick",
  "brown",
  "fox",
  "jumps",
  "over",
  "the",
  "lazy",
  "dog",
];

The first question is for the numbers array. The second question is for the words array.

You don't have to write an answer to the thought questions.

Every

  1. Determine if every number is greater than or equal to 2
  2. determine if every word shorter than 7 characters

Filter

  1. filter the array for numbers less than 5
  2. filter words that have an odd length

Find

  1. Find the first value divisible by 4
  2. find the first word that is longer than 4 characters

Find Index

  1. find the index of the first number that is divisible by 3
  2. find the index of the first word that is less than 2 characters long

For Each

  1. console.log each value of the nums array multiplied by 3
  2. console.log each word with an exclamation point at the end of it

Thought Questions

  • What happened to the original array?
  • Can you store the values from a forEach method in a new array?

Map

  1. Make a new array of each number squared and then multiplied by their index number
  2. Make a new array of all the words in all uppercase

Thought Questions

  • What happened to the original array?
  • Can you store the values from a map method in a new array?

Some

  • Find out if some numbers are divisible by 7
  • Find out if some words have the letter a in them

Hungry for More

Reduce

  • Add all the numbers in the array together using the reduce method
  • concatenate all the words using reduce

Thought Questions

  • What happened to the original array?

Sort

  • Try to sort without any arguments, do you get what you'd expect with the numbers array?
  • Try to sort without any arguments, do you get what you'd expect with the words array?
  • Sort the numbers in ascending order
  • Sort the numbers in descending order
  • Sort the words in ascending order
  • Sort the words in descending order

Thought Questions

  • What happened to the original array?

Array Methods Challenge Problems

isPanagram

Using the following array - test whether each letter a-z (case insensitive) is used at least once

const panagram = [
  "The",
  "quick",
  "brown",
  "fox",
  "jumps",
  "over",
  "the",
  "lazy",
  "dog",
];

Working with data

  • filter for products with a price that is less than 10, using the array below:
  • sort alphabetically by product name
const products = [
  {
    name: "fairy lights",
    price: 5.99,
    description: "festive holiday decoration",
  },
  {
    name: "banana",
    price: 0.99,
    description: "full of potassium",
  },
  {
    name: "egg separator",
    price: 3.99,
    description: "it separates yolks from whites",
  },
  {
    name: "flag",
    price: 5.99,
    description: "catches the breeze",
  },
  {
    name: "quark",
    price: 0.01,
    description: "Very small",
  },
  {
    name: "turtleneck",
    price: 19.99,
    description: "available in black and slightly-darker black",
  },
  {
    name: "mitt (leather)",
    price: 15,
    description: "regulation sized",
  },
  {
    name: "nothing",
    price: 10,
    description: "Hey, if you pay us, we won't ask any questions.",
  },
  {
    name: "violin",
    price: 2000,
    description: "Talk about a JS fiddle...",
  },
  {
    name: "yoyo",
    price: 1,
    description: "We had to pull some strings to get this one in.",
  },
];

array-method-drills's People

Contributors

krafalski avatar gitlep1 avatar abbreviatedman avatar meera-ramesh19 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.