Created
June 17, 2012 20:06
-
-
Save riquellopes/2945573 to your computer and use it in GitHub Desktop.
Simples solução para remover e adicionar elementos em um array.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Remove array element. | |
*/ | |
Array.prototype.rm = function(value) | |
{ | |
var arrays_s = this; | |
for( var i=0; i<this.length; i++) | |
{ | |
var obj = this[i]; | |
if( typeof obj === 'number' && obj == value ) | |
this.splice(i, 1); | |
}//for | |
return this; | |
}//function | |
/** | |
* Adds array element. | |
*/ | |
Array.prototype.add = function(value) | |
{ | |
var pos = 0, exist = false; | |
for( var i =0; i< this.length; i++ ) | |
{ | |
var obj = this[i]; | |
if( typeof obj === 'number' && obj == value ) | |
{ | |
pos = i; | |
exist = true; | |
}//if | |
}//for | |
if( !exist ) | |
this.push(value); | |
return this; | |
}//function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment