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
// Exercise 2 - Closures | |
// Wrap the following code in a closure and export only the "countdown" function. | |
// Code | |
(function(container, name){ | |
var index; | |
function log(){ | |
console.log(index); |
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
// Exercise 1 - OO || !OO | |
// Define a data structure for cars (make and color), and a function | |
// that logs a string like "I'm a red Mercedes" to the console. | |
// Make two versions: a functional version, and a object-oriented version. | |
function logCar (c) { | |
console.log("I'm a " + c.color + " " + c.make); | |
} |
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 Person (name) { | |
this.name = name; | |
} | |
Person.prototype.getName = function () { | |
return this.name; | |
} | |
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
// Part 1. | |
// Implement a function prototype extension that caches function results for | |
// the same input arguments of a function with one parameter. | |
Function.prototype.cached = function() { | |
var cache = {}, | |
func = this; | |
return function( arg ) { | |
return cache[ arg ] = arg in cache ? cache[ arg ] : func(arg); |
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
// 1 | |
document.getElementById('the_div').addEventListener( | |
'click', function(){ log('the_div!') }, true); | |
document.getElementById('the_list').addEventListener( | |
'click', function(){ log('the_list!') }, !true); | |
document.getElementById('the_item').addEventListener( | |
'click', function(){ log('the_item!') }, true); |
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
// Syntax | |
// ------ | |
// array.insertAt(index, element1, ..., elementN) | |
// Parameters | |
// ------ | |
// index | |
// : Index at which to insert elements. If negative, will begin that many elements from the end. | |
// element1, ..., elementN | |
// : The elements to add to the array. |
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(context) { | |
var xhr = context.XMLHttpRequest, | |
json = context.JSON, | |
mime = 'application/json'; | |
context.xhr = xhr && json && function(method, url, data, callback) { | |
var req = new xhr(); | |
req.onreadystatechange = function() { | |
if(req.readyState == 4) { |
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 updateClasses(el, options) { | |
var classes = el.className.split(/\s+/), | |
className, | |
pattern = /^no-(\w+)$/, | |
val, | |
i, l; | |
for (i = 0, l = classes.length; i < l; i++) { | |
className = classes[i]; | |
if (!options.hasOwnProperty(className)) { |
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
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE |
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
// returns a new sorted array with all elements from independently sorted arrays in arguments[1] thru arguments[n] | |
function mergeSorted(iterator/* ... arrays */) { | |
var result = [], | |
arrays = [].slice.call(arguments, 1), | |
indexes = [], | |
values = [], | |
len, | |
ix, | |
min; |
OlderNewer