Example of use
var list = new ArrayList();
list.add("c");
list.add("f");
list.add("a");
list.add("d");
list.add("e");
list.add("b");
list.remove("d");
alert('get(): ' + list.get());
alert('getSortedAsc(): ' + list.getSortedAsc());
alert('getSortedDesc(): ' + list.getSortedDesc());
function ArrayList() {
var _array = [];
this.add = add;
this.get = get;
this.remove = remove;
this.size = size;
this.toString = toString;
this.getElementIndex = getElementIndex;
this.getSortedAsc = getSortedAsc;
this.getSortedDesc = getSortedDesc;
this.isElementExists = isElementExists;
this.hasAnyNotNullElement = hasAnyNotNullElement;
function add(value){
_array.push(value);
}
function remove(value){
var toDelete = getElementIndex(value);
delete _array[toDelete];
}
function size(){
return _array.length;
}
function toString(){
var t = '';
for(var i = 0; i < size(); i++){
t += _array[i];
if(i < size() - 1) t += ', ';
}
return t;
}
function getElementIndex(value){
for(var i = 0; i < size(); i++)
if(_array[i] == value) return i;
return 'false';
}
function isElementExists(value){
return (getElementIndex(value) == 'false') ? false : true;
}
function hasAnyNotNullElement(){
for(var i = 0; i < size(); i++){
if(_array[i] != '' && typeof(_array[i]) != 'undefined')
return true;
}
return false;
}
function get(){
var tmp = [];
var j = 0;
for(var i = 0; i < size(); i++){
if(typeof(_array[i]) != 'undefined'){
tmp[j] = _array[i];
j++;
}
}
return tmp;
}
function getSortedAsc(){
var tmp = [];
tmp = get();
return tmp.sort();
}
function getSortedDesc(){
var tmp = [];
tmp = get();
tmp.sort();
return tmp.reverse();
}
}