Array Function Class

This is class that I used often in my works :) Hope you find it useful. It manipulates Array Object. It is user to add or remove element from a certain position.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.stanislavstankov.shared.utils {
   
    public final class ArrayFunction {
       
        /*------------------------------------
            Public methods
        ------------------------------------*/

        /**
         * Remove element from an array.
         * @param selectedArr Array from whom will be remove element;
         * @param elementIndex Removed index from array. Firts item is with index = 0;
         * @return New array with removed element;
        */

        public static function removeElement(selectedArr:Array, elementIndex:int):Array {
            var outArr:Array = [];
            outArr = outArr.concat(selectedArr.slice(0, elementIndex), selectedArr.slice(elementIndex + 1));
            return outArr;
        }
       
        /**
         * Add element at index position in array. If given elementIndex is bigger or equal of the lenght of array, element is added like last element
         * @param selectedArr Array from whom will be remove element;
         * @param elementIndex Removed index from array. Firts item is with index = 0;
         * @param newObj Object that will be added;
         * @return New array with removed element;
        */

        public static function addElement(selectedArr:Array, elementIndex:int, newObj:Object):Array {
            var outArr:Array = [];
            outArr = outArr.concat(selectedArr.slice(0, elementIndex), newObj, selectedArr.slice(elementIndex));
            return outArr;
        }
       
    }
}
Creative Commons License
This work, unless otherwise expressly stated, is licensed under a Creative Commons Attribution 2.5 Bulgaria License.

Comments are closed.