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
// taken from http://www.dreamincode.net/code/snippet154.htm | |
// | |
// Find the weaknesses, and clean up the code. | |
// Find at least 3 things you can make better! | |
// | |
// Test numbers (return true): | |
// 4111111111111111 | |
// 378282246310005 | |
// 5555555555554444 |
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 isCreditCard(CC) { | |
var sum = 0, | |
mul = 1, | |
l = CC.length, | |
i; | |
if ( l > 19 ) { | |
return 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
// Exercise 2 - Closures | |
// | |
// Wrap the following code in a closure and export only the "countdown" function. | |
// | |
// You're NOT ALLOWED TO CHANGE the existing code; you may only add code | |
// on top and/or below it! | |
myClosure = (function() { | |
var 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. | |
var logCar = function( car ) { | |
console.log( "I'm a " + car.color + " " + car.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
// Part 1. | |
// Implement a function prototype extension that caches function results for | |
// the same input arguments of a function with one parameter. | |
// | |
// For example: | |
// Make sin(1) have the result of Math.sin(1), but use a cached value | |
// for future calls. | |
// | |
// Part 2. |
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. Write a class to support the following code: | |
var Person = function( name ) { | |
this.name = name; | |
} | |
var thomas = new Person('Thomas'); | |
var amy = new Person('Amy'); | |
thomas.name // --> "Thomas" | |
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. Write a class to support the following code: | |
var Person = function( name ) { | |
this.name = name; | |
} | |
var thomas = new Person('Thomas'); | |
var amy = new Person('Amy'); | |
thomas.name // --> "Thomas" | |
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($, undefined) { | |
// Truncates a wrapper & provides a more link to show the content in full | |
$.fn.truncate = function( c ) { | |
return this.each( function() { | |
// Trucate, add class, add more link | |
var $wrapper = $(this).css( { 'height' : c.height, 'overflow' : 'hidden'} ).addClass('truncated').after('<span class="truncate-more">more</span>'); |
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
// Adds a matchHeight method to jQuery/zepto. | |
// Takes a jquery/zepto collection and makes them all as tall as the tallest elements | |
// Ideal for equal column layouts | |
// ## Paramaters | |
// * None (run on a zepto collection instead) | |
// ## Returns | |
// The collection which it was run on | |
// ## Example | |
// $('#myDiv1, #myDiv2').matchHeight(); | |
// #test |
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
#!/usr/bin/env ruby | |
isbn_array = [] | |
def to_isbn string | |
if ( string.gsub("\n", "") ) | |
string.gsub!("\n", "") | |
end | |
if ( string.gsub!(" ", "") ) | |
string.gsub!(" ", "") |
OlderNewer