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
map([ 'a', 'b', 'c' ], function( value ) { | |
return value.toUpperCase(); | |
}); // [ 'A', 'B', 'C' ] |
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
function isEven(val){ | |
evaluate: { // Block label, not an object literal | |
if ( val % 2 == 0 ) break evaluate; | |
return false; | |
} | |
return true; | |
} | |
isEven(4) // true | |
isEven(7) // false |
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
i=0;while(i++<100)console.log(((i%3?'':'Fizz')+(i%5?'':'Buzz'))||i) |
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
for(i=0;i++<100;)console.log(((i%3?'':'Fizz')+(i%5?'':'Buzz'))||i) |
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
var url = 'monoSound.wav' | |
, audio = new Audio(url) | |
, context = new webkitAudioContext() | |
, processor = context.createJavaScriptNode(512, 1, 1) | |
, sourceNode | |
audio.addEventListener('canplaythrough', function(){ | |
sourceNode = context.createMediaElementSource(audio) | |
sourceNode.connect(processor) | |
processor.connect(context.destination) |
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
var url = 'http://static1.kevincennis.com/sounds/callmemaybe.mp3' | |
, audio = new Audio(url) | |
, context = new webkitAudioContext() | |
, waveShaper = context.createWaveShaper() | |
, bassify = context.createBiquadFilter() | |
, sourceNode | |
audio.addEventListener('canplaythrough', function(){ | |
sourceNode = context.createMediaElementSource(audio) | |
sourceNode.connect(waveShaper) |
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
var arr = [1,2,3,4,5,6,7,8,9] | |
var sum = eval(arr.join('+')) |
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
// Y Combinator | |
// λf.(λg.f(λy.g g y))(λg.f(λy.g g y)) | |
// | |
// derives the fixed-point of the input function | |
// such that Y( f ) and f( Y( f ) ) are computationally equivalent | |
function Y( f ) { | |
return (function( g ) { | |
return f(function( y ) { |
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
function memoize( fn ) { | |
const map = new Map(); | |
const key = Symbol('key'); | |
return function() { | |
let item = map; | |
let cached = false; | |
for ( let i = 0; i < arguments.length; ++i ) { | |
let cache = item.get( arguments[ i ] ); |
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
function img2table( img ){ | |
var canvas = document.createElement('canvas') | |
, ctx = canvas.getContext('2d') | |
, table = document.createElement('table') | |
, width = canvas.width = img.width | |
, height = canvas.height = img.height | |
, pixels | |
, i, j, l1, l2 | |
, tr, td, r, g, b |