// ********************************************************************** // * Librería de Funciones de Moisés García (MoiK78) * // * http://www.moik78.com/ * // ********************************************************************** // :::::::::::::::::::::::::::::::::::::::::: // : METODOS PARA ARRAYS : // :::::::::::::::::::::::::::::::::::::::::: // // ============================================================ // Devuelve el número de veces que encuentra un valor en un array // // Ej.: // _root.miarray=new Array("apple","pear","apple","orange") // numeroApple=_root.miarray.Count("apple") => 2 // ============================================================ // Array.prototype.Count=function(value) { var cont; for(var i=0;i < this.length;++i){ if(this[i] == value){ ++cont; } } return cont; } // ============================================================ // Elimina valores duplicados en un array siendo cada valor único // // Ej.: // _root.miarray=new Array("apple","pear","apple","orange") // _root.miarray.Unique() => ("apple","pear","orange") // ============================================================ // Array.prototype.Unique=function(){ for(var i=0;i < this.length;++i){ for(var j=(i+1);j <= this.length;++j){ if(this[i] == this[j]){ this.splice(j,1) } } } } // ============================================================ // Busca un valor en la matriz y devuelve la primera posicion // donde lo ha encontrado // Ej.: // myArray = new Array("apple", "pear", "banana", "orange"); // applePosition = myArray.SearchFirst("apple"); // if (applePosition != -1) { // trace("Apple found in position "+applePosition); // } else { // trace("Apple not found"); // } // ============================================================ // Array.prototype.SearchFirst=function(value) { for(var i=0;i < this.length;i++){ if(this[i] == value){ return i; } } return -1; } // ============================================================ // Busca un valor en la matriz y devuelve la ultima posicion // donde lo ha encontrado // Ej.: // myArray = new Array("apple", "pear", "apple", "orange"); // applePosition = myArray.SearchLast("apple"); // if (applePosition != -1) { // trace("Apple found in position "+applePosition); // } else { // trace("Apple not found"); // } // ============================================================ // Array.prototype.SearchLast=function(value) { for(var i = this.length-1;i > -1;--i){ if(this[i] == value){ return i; } } return -1; } // ============================================================ // Copia un array en vez de crear una referencia a un array // Ej.: // tester=[1,2,3,4] // tester2=tester.Copy() // ============================================================ // Array.prototype.Copy=function(){ return this.slice(0) } // ============================================================ // Compara dos arrays y comprueba a ver si son iguales. Si son // iguales devuelve true, si no devuele false. // Ej:. // array1 = [1, 2, 3, 4]; // array2 = ["1", 2, 3, 4]; // if (array1.IdenticalArray(array2)) { // trace("The arrays are identical"); // } else{ // trace("The arrays are NOT identical"); // } // ============================================================ // Array.prototype.IdenticalArray = function (Array2) { for(var i=0;i