Tag Archive | "Array"

Tags: , ,

Array.diff

Posted on 19 February 2010 by michael

Just had some fun with Javascript (and Prototype):

Continue Reading

Comments (0)

Tags: , ,

[UPDATE] Array.filter

Posted on 04 September 2008 by michael

Hab’ mich noch zu einer kleinen Verbesserung verleiten lassen…

Object.extend(Array.prototype, {
    filter : function(){
        var args = $A(arguments), fnc = args.shift(), tmpNew = new Array();
        if(typeof(fnc)!='function'){throw new TypeError()};
        this.each(function(element){
            args.unshift(element);
            if (fnc.apply(this,args)) {
                tmpNew.push(element)
            }
            args.shift();
        });
        return tmpNew;
    }
});

Damit sind jetzt u.a. weitere Paramater für die Testfunktion zulässig:

[1,2,3,4,5,6,7,8].filter(function(element,a,b){return element > a && element < b;},3,6);
// => [4, 5]
[1,2,3,4,5,6,7,8].filter(function(element){return element > 6;});
// => [7,8]
[1,2,3,4,5,6,7,8].filter(1,3,6);
// => TypeError
['aa',1,9,{},[],'bb'].filter(function(e,a){return typeof(e)==a},'number').filter(function(e,a){return e > a},8)
// => [9]

Comments (0)

Tags: , ,

Array.max und Array.min

Posted on 03 September 2008 by michael

Zwei kleine triviale Zusätze für meine Array-Erweiterungen…
Continue Reading

Comments (0)

Tags: , ,

Array.filter

Posted on 29 August 2008 by michael

Mir war es einfach zu langweilig, jedesmal ein .each oder ähnliches auf Arrays machen zu müssen, nur um ein Array zu filtern. Also ab damit in das Array-Objekt!
Continue Reading

Comments (0)

Tags: , ,

Array.compare

Posted on 20 August 2008 by michael

Für einen “Test” musste ich 2 unsortierte Arrays vergleichen können. Daher habe ich diese kleine Erweiterung zu prototype’s Array-Object geschrieben. Continue Reading

Comments (0)

Photos from our Flickr stream

See all photos

josi_de@twitter

GitHub Projects