Skip to content

Instantly share code, notes, and snippets.

@damwhit
Last active June 1, 2018 16:15
Show Gist options
  • Save damwhit/cb2f9946182e1a479be525b59b7f5b42 to your computer and use it in GitHub Desktop.
Save damwhit/cb2f9946182e1a479be525b59b7f5b42 to your computer and use it in GitHub Desktop.
Array Prototype Practice!

Return the first string

With an array that is mostly boolean, write a function that will return the first string.

For example, if we have the following array:

var things = [
  true,  true,  true,  false,
  true,  true,  1,  true,
  true,  false, true,  false,
  true,  'hello', false, true,
  true,  true,  true,  true,
  false, false, 'world',  true
];

The correct answer would be hello.

Return an array that is in reverse alphabetical order

For example, if we have the following array:

var words = ['hi',  'hello', 'carrot', 'world'];

The correct answer would be ['world', 'hi', 'hello', 'carrot'].

Return the 3rd and 5th elements from an array in a new array

For example, if we have the following array:

var words = ['hi',  'hello', 'car', 'cool', 'blah'];

The correct answer would be ['car', 'blah'].

Return an array of crusts

For example, if we have the following array:

var pizzas = [
  { crust: 'deep dish' },
  { crust: 'pan' },
  { crust: 'thin' },
];

The correct answer would be ['deep dish', 'pan', 'thin'].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment