Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ejemplo para extender la funcionalidad de los arreglos.
Array.prototype.random = function () {
var self = this
var conteo = self.length
var temp, x
for (var i = conteo - 1; i >= 0; i--){
temp = self[i]
x = Math.floor(Math.random() * conteo)
self[i] = self[x]
self[x] = temp
}
return self
}
/*
Después de agregar la función shuffle en los arreglos se puede utilizar directamente
var foo = [1,2,3,4,5,6]
foo.random()
*/
Array.prototype.remove = function (element) {
var index = this.indexOf(element)
if (index != -1) {
this.splice(index, 1)
}
return this
}
/*
var test = [1,2,3,4,5]
test.remove(3)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment