Algorithm Book - Chapter 3 - Arrays Flashcards
What are array inspection functions?
min(arr), max(arr), sum(arr), avg(arr)
What scenarios are arrays good for? not good for?
Arrays are good for random-access and to be read in a differen roder than they were added. Arrays are less suitable (still common) in scenarios with many insertsiona d removals.
Arrays can be sparse? explain
You can push values at arr.length +1..the value at arr.length would be undefined.
Describe passing by reference
Arrays are passed by reference. This means that a pointer is sent when an array is sent as an argument. Therefore, even though parameters are always copies of originals, with arrays (and all objects) a pointer is copied, resulting in caller and callee both having a copy of the same pointer. Hence both are looking at the same location in memory, and hence both will reference the same array. When you pass an array to a function, that array is “live”: changes the callee makes in that array will be reflected when we return to the caller, regardless of whether the called function returns that array.
Javascript is loosely written
Because of it’s data types. JavaScript considers almost everything an object, since almost every possible values has a set of methods attached (valueOf, toString, etc.)
What are the data types?
Boolean, Number, String, Object, Function, and undefined.
Describe falsey and truthy
Six values are nothing: false, 0, NaN, “”, null, undefined
Truthy: objects, functions, non-0 numbers and non-empty strings