spudly.shuoink.com

the best way to predict the future is to implement it

Entries Comments


Month: June, 2008

String.interpolate()

19 June, 2008 (21:39) | JavaScript | 1 comment

Here’s a string prototype that allows you to interpolate variables into a string (ruby style). All you have to do is create your template and call interpolate on it ( with an object literal as a parameter for the vars to interpolate ).
Example:
var template = “The #{foxAdj}, #{foxAdj2} fox jumped over the #{dogAdj} dog.”;

// alert [...]

Array.each();

3 June, 2008 (06:48) | General | 3 comments

Here’s my version of the popular array.each method.
Array.prototype.each = function() {

if ( this.cursor === undefined ) {
this.cursor = 0;
} else if ( this.cursor > this.length - 1 ) {
this.cursor = undefined;
return;
[...]

Array.min() && Array.max() && Array.sum()

1 June, 2008 (19:38) | General | 2 comments

Here’s three array methods that might be useful: min(), max(), and sum(). I’m sure you can guess what they do, but I’m going to tell you anyway. Note that for all three functions, the entire array must have only numeric values.
First, we have min(). This finds the smallest number in the array and returns it.
Usage: [...]