Skip to content

Instantly share code, notes, and snippets.

View tjeastmond's full-sized avatar
😪
Job Hunting

TJ Eastmond tjeastmond

😪
Job Hunting
View GitHub Profile
var memoizer = function(memo, func) {
var recur = function(n) {
var result = memo[n];
if (typeof result !== 'number') {
result = func(recur, n);
memo[n] = result;
}
return result;
};
return recur;
for (var i = 1; i <= 100; ++i) {
var f = i % 3 === 0, b = i % 5 === 0;
console.log(f ? b ? 'FizzBuzz' : 'Fizz' : b ? 'Buzz' : i);
}
var isInteger = function(x) { return (x ^ 0) === x; };
function isPrime(number) {
if (typeof number !== 'number' || !isInteger(number)) {
// Alternatively you can throw an error.
return false;
}
if (number < 2) {
return false;
@tjeastmond
tjeastmond / JSModule.js
Last active October 2, 2015 08:18
JS Module Pattern - Simple example for a friend
(function() {
var SpotifySearch = window.SpotifySearch = function() {
};
}).call(this);
@tjeastmond
tjeastmond / when.js
Created March 21, 2012 20:24
Underscore.js Mixin that takes two functions as arguments, and returns a new function that when called will run the first function until it returns true. When the first function returns true, the second function is fired.
// When.js
// TJ Eastmond <[email protected]>, SpiteShow
// Simple Underscore.js Mixin that runs the first function until
// it returns true, then runs the second
(function() {
// Pass in two functions. The first is checked until it returns true, then the second is run
var when = function(truthy, func) {
// Just making sure we were passed functions...