das haar in der suppe

ajax, entwicklung, javascript — enodyt @ 1:04 am

stell dir vor du sitzt vorm computer und hast dein javascript erweiterungs-library nicht zur verfügung …

ja, genau: die frisur ist zersaust, der array nicht und ob obiger titel zutrifft, läßt sich auf die schnelle auch nicht sagen.

// shuffle
Array.prototype.shuffle = function() {
  for (var j,x,i = this.length; i;
       j = parseInt(Math.random()*i),
       x = this[--i], this[i] = this[j], this[j] = x);
}

// in_array like method
Array.prototype.contains = function(el) {
  for (var i = 0; i < this.length; i++)
    if (this[i] == el) return true;
  return false;
}

/* Usage:
var a = new Array('a', 'c', 'd', 'f');
if (a.contains('b')) alert('Yeah! Beh');
a.shuffle();
alert(a.toString());
*/

heutzutags ist dieses post mindestens einen -tag wert.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2009 enodyt.zapzarap.net/blog | powered by WordPress with Barecity, running in doloops