function Tuple(/* values */) {
var args = Array.prototype.slice.call(arguments, 0);
this._store = new Array(args.length);
this.pack.apply(this, args);
}
Tuple.prototype.pack = function pack(/* values */) {
var store = this._store;
var i = store.length;
while (i--) {
store[i] = arguments[i];
}
return this;
};
Tuple.prototype.unpack = function unpack(callback) {
return callback.apply(this, this._store);
};
Tuple.prototype.toString = function toString() {
return ['(', this._store.join(', '), ')'].join('');
};
Tuple.prototype.valueOf = function valueOf() {
var store = this._store;
var storeLength = store.length;
var total = store[0];
var i;
for (i = 1; i < storeLength; i += 1) {
total += store[i];
}
return total;
};
var box = new Tuple(10, 20, 15);
var volume = box.unpack(function (x, y, z) {
return x * y * z;
});
console.log(volume); // 3000
var p1 = new Tuple(10, 20);
var p2 = new Tuple(40, 50);
console.log(p2 + p1); // true
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.