6/26/2017 - 12:33 AM

Unit 2-Lesson 4: Arrays and Loops (additional material)

Unit 2-Lesson 4: Arrays and Loops (additional material)

This method sorts an array in place. In place means that this method sorts the original array;

It does not copy the array, sort it, and then return the sorted copy.

If you pass no arguments to .sort(), it will alphabetically sort the list by default

string example
sorting ordinal numbers

.slice(begin, end)

you can use negative values for the begin parameter in order to select the last n numbers of an array.

from begin to end(end not included)

orginal array is not modified

slice method
return a portion of an existing array
<a href=",console,output" target="_blank>slice removing last 2 from array

this method applies a function to each item in a collection, but it does not return an array of transformed elements

better example
converting from For Loop to .forEach


creating an array
accessing an array
<a href=",console,output>Map to produce HTML elements

This is useful for aggregating array data. This method iterates over the array while maintaining an accumulation object. This object is returned inside the reduce function and is passed into the subsequent iteration.

reduce method
another reduce method

This method is used to find a single item in an array.

find method
find an object in an array by one of its properties

This method is used to take one array of items, and make a new one that contains only items that a filtering function returns true for.

filter long words
filtering out all small values