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
/** | |
* JavaScript Max Challenge: | |
* A function that returns the greater of 2 numbers | |
* without using math.min, math.max, >, <, ==, != | |
* | |
* ie: | |
* given a > b | |
* assert max(a, b) == a | |
* | |
* Solution: |
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 alphabet = "abcdefghijklmnopqrstuvwxyz".split(""); | |
var order = "desc"; | |
alphabet.sort(function (a, b) { | |
return | |
a == b | |
? 0 | |
: (order == "desc" ? -1 : 1) | |
* (a < b ? -1 : 1); | |
}); |
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
// Execute this and look at your console errors. | |
// this ... | |
(function __I_HAVE_A_NAME_NOW__ () { | |
// deliberate error | |
catchMeIfYouCan(); | |
})(); | |
// ... debugs far better this anonymous function |
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
// Uber typeof: | |
// Since null, in JavaScript, is an object with an unknown value, | |
// typeof null == 'object' is technically correct. | |
// Nevertheless, JavaScript's typeof operator could be much more helpful | |
// than it is. | |
function typecheck (obj) { | |
var type; | |
// faster than if/else | |
switch (obj) { |