Last active
August 29, 2015 14:25
-
-
Save jordanwilhite/3b9196d776eb557552f9 to your computer and use it in GitHub Desktop.
javascript functions for will.
This file contains 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
//_.compact | |
var x = [0, 17, 322, '', 2354]; | |
var newX = _.compact(x); | |
//newX is [17, 322, 2354] | |
// Usefulness: In a massive program, im thinking like bank numbers or credit-card numbers, something like _.compact would be useful because it could discard numbers that were typed incorrectly. | |
//_.compact removes things from an array that equate to false, null, NaN, etc. and makes them easier to read. | |
//_.union | |
var x = ([1, 2, 3, 4, 13, 25, 64, 101],[1, 2, 13, 6, 1, 25], [2, 4, 4, 101]); | |
var newX =_.union(x) | |
// newX = [2, 4, 101] | |
//Usefulness: I think that _.union could come in handy when doing things like statistics or in finding averages. | |
//_.union is used to combine repeated numbers in multiple arrays into one array | |
// _.once | |
function agreeToTerms() {console.log('I agree');} | |
var newTerms = _.once(agreeToTerms); | |
// newTerms(); Logs 'I agree' | |
// newTerms(); noting happens | |
//_.once is used to create a new function that only runs one time. i.e. a Terms of Service agreement. | |
//_.compose | |
var greet = function(name){return "Hello: " + name; }; | |
var exclaim = function(statement){return statement.toUpperCase() + "!"; }; | |
var welcome = _.compose(greet, exclaim); | |
var output = welcome('jordan ' + 'wilhite'); | |
// logs Hello: JORDAN WILHITE! | |
// can be used as a login prompt | |
//_.keys | |
var x = ({seven: 7, twelve: 12, thirty: 30}); | |
var newX = _.keys(x); | |
// ['seven', 'twelve', 'thirty'] | |
//_.values | |
var x = ({one: 1, two: 2, three: 3}); | |
var newX = _.values(x); | |
// [1, 2, 3] | |
// _.keys and _.values work in similar fashions. _.keys takes looks at both the id and the number and logs the id and ignores the number. _.values looks at the id and the value and logs the value and ignores the id. | |
//_.random | |
var x = ''; | |
var newX = _.random(0, 800000000); | |
//newX = a random number each time it's ran. For instance, for me, it logged 159212083, 330480747, & 667582456 on three seperate occasions. | |
// _.random logs a random number in the set range. | |
//_.now | |
var x = ''; | |
var newX =_.now(); | |
// newX = 1437536189241 | |
//logs the interger timestamp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment