Identify that strings are immutable and arrays are mutable
Mutable | Immutable |
---|---|
Array | Number |
Object | String |
Boolean |
Define a function using both function declaration and function expression syntax
Utilize Array#push, #pop, #shift, #unshift to mutate an array
List the arguments that can be used with Array#splice
Write a function that sums up elements of an array, given an array of numbers as an argument
Utilize Array#forEach, #map, #filter, #reduce in a function (Thursday Material)
Array.forEach : method that executes a provided function once for each array element.
map : creates a new array populated with the results of calling a provided function on every element in the calling array.
filter : creates a new array that passes the test implemented by the provided function.
reduce : executes a reducer function (that you provide) on each element of the array, resulting in a single output value.
Define a function that takes in an array of numbers and returns a new array containing only the primes (Uses Thursday Material: Helper Functions)
let nums = [1, 3, 42, 14, 21, 30, 11];
function getPrimes(arr) {
let result = [];
for (var i = 0; i < nums.length; i++) {
if (arr[i] === 1) continue;
if (isPrime(arr[i])) {
result.push(arr[i]);
}
return result;
}
function isPrime(number) {
for (var i = 2; i < number; i++) {
if (number % i === 0) {
return false;
}
}
return number > 1;
}
console.log(getPrimes(nums)); // 3, 11
Define a function that takes in a 2D array of numbers and returns the total sum of all elements in the array
Define a function that takes in an array of elements and returns a 2d array where the subarrays represent unique pairs of elements
Define a function that takes in an array of numbers as an argument and returns the smallest value in the array; if the array is empty return null