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
| var peeps = { hugh: { name: 'hugh jackson' } } | |
| var titleCase = function(str){ | |
| return str.split(' ').map(function(str){ return str.substr(0, 1).toUpperCase() + str.substr(1) }).join(' ') | |
| } | |
| var val = maybe(peeps) | |
| .map(function(peeps){ return peeps.tahir }) | |
| .map(function(peep){ return peep.name }) | |
| .map(titleCase) | |
| .getOrElse('couldn\'t find person') |
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
| $ flesh-out require('my-module').toNumber | |
| provide type signature for inputs | |
| > Int | |
| What do you expect for: NaN? | |
| > NaN | |
| What do you expect for: Infinity? | |
| > Infinity |
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
| // as an approximation of the classical model, Num will return an object with methods on it | |
| // these methods cannot be added to at run-time for all numbers, since there's no prototype | |
| // chain going on here | |
| var Num = function(val){ | |
| return { | |
| val: val, | |
| mul: function(val) { return Num(this.val * val) }, | |
| div: function(val) { return Num(this.val / val) }, | |
| add: function(val) { return Num(this.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
| var validators = { | |
| password: function(pass) { | |
| return /[0-9]/.test(pass) && pass.length > 10 | |
| } | |
| } | |
| var validate = function(el){ | |
| return validators[el.getAttribute('data-validator')](el.value) | |
| } |
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
| var toArray = function(val){ return [].slice.call(val) } | |
| toArray(document.getElementsByTagName('a')).forEach(function(node){ | |
| node.href = "http://hughfdjackson.com" | |
| }) |
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
| "this is a really long string this is a really long string this is a really long string this is a really long string this is a really long string this is a really long string this is a really long string this is a really long string this is a really long string this is a really long string this is a really long string" | |
| var f = function(){ | |
| var str = "this is a really long stringthis is a really long stringthis is a really long stringthis is a really long stringthis is a really long stringthis is a really long stringthis is a really long stringthis is a really long stringthis is a really long string" | |
| var short = "str" | |
| console.log('i love js muchly') | |
| } | |
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
| var jumble = function(arr){ | |
| return arr.slice().sort(function(){ return Math.random() > 0.5 }); | |
| }; |
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
| // generators make random content of a type | |
| // -- utils | |
| var randNth = function(coll) { | |
| return coll[Math.floor(Math.random() * coll.length)] | |
| } | |
| var randChar = function(){ | |
| return randNth('qwertyuiopasdfghjklzxcvbnm') | |
| } |
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
| void function(root){ | |
| var data = new WeakMap | |
| var meta = function(o, v){ | |
| if ( arguements.length === 1 ) return data.get(o) | |
| else return data.set(o, v) | |
| } | |
| root.meta = meta |
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
| $(function() | |
| { | |
| $.ajax({ | |
| url: 'check.php', //the script to call to get data | |
| success: function(data) { | |
| $('#count').html(data); //Set output element html | |
| } | |
| }); | |
| }); |