This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*each takes an array and a callback function which passes | |
| (value, index, collection) as its arguments. Each works on | |
| both arrays and objects and does not work with a return within | |
| the body. | |
| */ | |
| _.each = function each(collection, myFunction){ | |
| if(_.typeOf(collection) === 'array'){ | |
| for(var i = 0; i < collection.length; i++){ | |
| myFunction(collection[i], i, collection); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| _.last = function last(arr, number){ | |
| var newArr = []; | |
| if(!Array.isArray(arr)){ | |
| return []; | |
| }else if(isNaN(number) || number === undefined ){ | |
| return arr[arr.length - 1]; | |
| }else if(number < 0){ | |
| return newArr; | |
| }else if(number > arr.length){ | |
| return arr; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //first takes an array and a number and returns that amount | |
| //of values from the beginning of an array in a new array. | |
| _.first = function first(arr, number){ | |
| var newArr = []; | |
| if(!Array.isArray(arr)){ | |
| return []; | |
| }else if(isNaN(number) || number === undefined ){ | |
| return arr[0]; | |
| }else if(number < 0){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //takes any value and returns that value's type as a string | |
| _.typeOf = function typeOf (anything){ | |
| if(anything === null) { | |
| return anything = "null"; | |
| }else if(Array.isArray(anything)){ | |
| return "array"; | |
| } | |
| return typeof anything; | |
| } | |
| //typeOf with them arrows!! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //identity- takes any value and returns that exact value. | |
| _.identity = function identity(anything) { | |
| return anything; | |
| }; | |
| //using arrow fun... so clean | |
| identity = (val) => val; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*Variables-our friends in the age of repetition | |
| Variables are placeholders which allow programs to easily recall | |
| information or actions, alter them, and implement complex operations | |
| in a clear concise manner. They can be thought of as containers for | |
| holding values of any data type including numbers, strings, booleans, | |
| and even functions or objects. | |
| */ | |
| /*declaring a variable called num1 with "var" keyword | |
| this simply creates a place in memory which can then be assigned to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Functions: programs within programs. | |
| //a dream within a dream | |
| //two phases of functions are declaration and invocation(or calling) | |
| // declaration (anonymous function being declared as variable) | |
| // | |
| var fullName = function(first, middle, last){ | |
| var person = { | |
| FirstName: first, | |
| MiddleName: middle, | |
| Last: last |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Loops: while, for, for in. | |
| // Making your way through the world today. | |
| // while loops address a condition and execute the code within {} as | |
| // long as that statement holds true | |
| "use strict"; | |
| var x = 0; | |
| while (x === 0) {} | |
| //console.log("we're ready for something"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Functions: programs within programs. | |
| //a dream within a dream | |
| var fullName = function(first, middle, last){ | |
| var person = { | |
| FirstName: first, | |
| MiddleName: middle, | |
| Last: last | |
| } | |
| var newName = first + " " + middle + " " +last; | |
| console.log(newName); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Loops: while, for, for in. | |
| // Making your way through the world today. | |
| // while loops address a condition and execute the code within {} as | |
| // long as that statement holds true | |
| "use strict"; | |
| var x = 0; | |
| while (x === 0) { | |
| console.log("we're ready for something"); | |
| } |