#3 ✓not_for_core
Claudio Bertarelli

Userfull Array Functions

Reported by Claudio Bertarelli | April 11th, 2008 @ 08:42 PM

    Object.extend(Array.prototype, {
        /* Add an array after the last index of an array */
        Add : function(object){
            this[this.length] = object;
        },
        
        /* Add an array on the index and dislocated the intens to the botton index*/
        AddAt : function(object, index){
            if(Object.isNumber(index)){
                var newArray = this.clone();
                for(i=0;i<newArray.length+1;i++){
                    if(i == index){
                        this[i] = object;
                    }else{
                        this[i] = newArray[i];
                    }
                }
            }
        },
        
        /* Exchange the source index to the destnation index */    
        Exchange : function(source, dest){
            if(Object.isNumber(source) && Object.isNumber(dest)){
                var newArray = this.clone();
                for(i=0;i<newArray.length;i++){
                    if(i == source){
                        this[i] = newArray[dest];
                    }else if(i == dest){
                        this[i] = newArray[source];
                    }else{
                        this[i] = newArray[i];
                    }
                }
            }
        }              
    })

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

People watching this ticket

Referenced by

Pages