Giter Club home page Giter Club logo

array_methods_assignment's Introduction

Exercises

NOTE: DO NOT USE THE BUILT IN METHODS WHEN ASKED TO MAKE THEM!

  1. Using Array.prototype add a new method myForEach that mimics the behaivor of the built in forEach.

  2. Use your myForEach to add myMap to the Array prototype. myMap should behave the same as regular map.

  3. Write a 'myFilterthat behave's the same asfilter`.

  4. Write a myEvery.

  5. Write a myReduce. It should use the first element in the array if none is given.

  6. Write a myTranspose. This function should transpose a matrix. Exp:

let mtx = [
            [1, 2],
            [3, 4],
            [5, 6]
          ]

mtx.myTranspose();

// => [
        [1, 3, 5],
        [2, 4, 6]
       ]
  1. Use myMap to build a new array where every element is incremented by 10.
  2. Use myMap to build a new array where every non-string element is converted to an empty string.
  3. Use myFilter to get only the even elements in an array.
  4. Use myEvery to check if all elements in the array are the same.
  5. Use myReduce to return the sum of every element in an array.
  6. Use myMap to build a new array that doubles each element. Then chain myReduce to find the product of all the elements.
  7. Use myReduce to find the largest number in an array.
  8. Write a function elementDivisibleBy with parameters divisor and arr. Use myFilter to return a new array of every element of arr that can be evenly divided by divisor.
  9. Write a myJoin function.
  10. Write a mySlice function.
  11. Write a function countZeroes, which takes an array of numbers as its argument and returns the amount of zeroes that occur in it. Use reduce.
  12. Write a numberTimesIdx that uses map and multiples each number in the array by it's index.

Bonus: Write a myFlatten. This should take a multi-dimensional array and return it as one array.

let arr = [1, 2, [3, 4, 5, [6, 7, 8]]]
  arr.myFlatten();
  // => [1, 2, 3, 4, 5, 6, 7, 8]

array_methods_assignment's People

Contributors

coreyladovsky 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.