Skip to content

Instantly share code, notes, and snippets.

@PrimeTimeTran
Created September 11, 2019 03:17
Show Gist options
  • Save PrimeTimeTran/9dcfec98f8901b710e8aa34c366467bd to your computer and use it in GitHub Desktop.
Save PrimeTimeTran/9dcfec98f8901b710e8aa34c366467bd to your computer and use it in GitHub Desktop.
# Arrays Exercise
Here we'll go through some arrays that highlight the various Array Methods in JavaScript.
```
const inventors = [
'Albert Einstein',
'Issac Newton',
'Galileo Galilei',
'Marie Curie',
'Johannes Kepler',
'Nicolaus Copernicus',
'Max Planck',
'Katherine Blodgett',
'Ada Lovelace',
'Sarah E. Goode',
'Lise Meitner',
'Hanna Hammarstrom'
];
const numbers = [1, 2, 3, 5, 8, 13, 21, 34, 55];
```
### Filter
* Print out an array of the inventors whose name starts with 'A'.
* Print out an array of the inventors whose name contains 'n'.
* Bonus: print out an array of the inventors whose name has the same letter twice in a row (e.g. nn or mm).
* Print out an array of the numbers which are odd.
* Print out an array of the numbers that have two digits.
* Bonus: print out an array of the numbers which are prime.
### Map
* Print out an array of all the inventors' names in uppercase.
* Print out an array of all the first names of each inventor.
* Print out an array of the length of every name.
* Print out an array of every number multiplied by 100.
* Print out an array of the powers of two as shown by this array (e.g. 2, 4, 8, 16 ....).
### Sort
* Sort all the inventors in alphabetical order, A-Z.
* Sort all the inventors in reverse alphabetical order, Z-A. Do _not_ use the `reverse` method.
* Sort all the inventors by length of name, shortest name first.
* Sort all the inventors by length of name, longest name first. Do _not_ use the `reverse` method.
* Sort the numbers until you see the following: [1, 10, 11, 12, 13, 2, 3, 4, 5, 6, 7, 8, 9].
### Reduce
* Find the sum of all the numbers.
* Find the sum of all the even numbers.
* Create a string that has the first name of every inventor.
### Some / Every
* Does any inventor have the letter 'y' in their name?
* Does every inventor have the letter 'e' in their name?
* Does every inventor have first name that's longer than 4 characters?
### Find / FindIndex
* Find the inventor that has a middle name.
* Bonus: Return a new array without inventor with a middle name.
### Rocket 1
That number array is called the Fibonacci Sequence. Every number is the sum of the two previous numbers. Create a function, `fib(n)` that gives you the nth entry.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment