Skip to content

Sarah-Schmid/week3

Repository files navigation

Arrays Notes

Arrays are a data type that allow us to group similar variables together and refer to the values by location

Arrays keep up from having to make a new variable for each data point

Arrays are 0 based so the very first element in the array is always 0

Array is denoted with square barackets

You can add data to an array with the push command

You can call a unique value in an array using the Array name, square brackets and the value's location in the brackets

Using a for loop to do something to each element in an array, or to print out each element in an array is very common

Functions Notes

Code that you may want to use multiple times, but not in a loop

Functions are named blocks of modularized code

Any code within the {} while defining a fuction is the function body. This is the code that will be reused every time the function is called

To call the function just write the fuction name with paranthesis

A parameter is a part of the delcration of the function and an argument is used when envoking the function

You should not have more than 3 parameters for best practice

Parameters are jst place holders

Parameters are the parking spots and the arguments are the cars

"return" nothing will be printed out in the console

return statement is useful to give something back without logging it

function names should be verb and descriptive for best practice

Intermediate Array

The map method is used to evoke a function for each element in an array and then create a new array from the returned values

This is useful for when you need to transform the data in an array

Reduce method will take all the values in an array and reduce them down to one value

An examplew ould be summing all the values,or returning an average

filter returns a new array that contains all of the elements where the invoked method returns true (uses a boolean filter on an array to create a new array)

Splice can alter the contents of an array by adding, removing or modifying elements in an array at a specific location in an array (the first parameter is the location to start at, the second parameter is how many elements to removed) the Splice method returns an array of all the elements removed

week3

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published