<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comentarios en: Array.every(), por cada elemento</title>
	<atom:link href="http://www.anieto2k.com/2008/12/03/arrayevery-por-cada-elemento/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.anieto2k.com/2008/12/03/arrayevery-por-cada-elemento/</link>
	<description>Desarrollo web, Wordpress, y alguna cosilla más</description>
	<lastBuildDate>Sun, 12 Feb 2012 12:01:25 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>Por: gbt2908</title>
		<link>http://www.anieto2k.com/2008/12/03/arrayevery-por-cada-elemento/#comment-52451</link>
		<dc:creator>gbt2908</dc:creator>
		<pubDate>Fri, 05 Dec 2008 03:49:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.anieto2k.com/?p=6957#comment-52451</guid>
		<description>anieto ese fue un comentario repetido, lo volvi a postear porque no aparecia, y reciend despues lei donde dice &quot;Si tu comentario no aparece, puede ser que akismet lo haya capturado, cada día lo reviso y lo coloco en su lugar.&quot; perdon ^^ si queres borra el repetido (el anterior a este)</description>
		<content:encoded><![CDATA[<p>anieto ese fue un comentario repetido, lo volvi a postear porque no aparecia, y reciend despues lei donde dice &#8220;Si tu comentario no aparece, puede ser que akismet lo haya capturado, cada día lo reviso y lo coloco en su lugar.&#8221; perdon ^^ si queres borra el repetido (el anterior a este)</p>
]]></content:encoded>
	</item>
	<item>
		<title>Por: gbt29</title>
		<link>http://www.anieto2k.com/2008/12/03/arrayevery-por-cada-elemento/#comment-52419</link>
		<dc:creator>gbt29</dc:creator>
		<pubDate>Wed, 03 Dec 2008 19:03:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.anieto2k.com/?p=6957#comment-52419</guid>
		<description>hice el metodo each y algunos mas:

&lt;pre&gt;&lt;code&gt;
extend({
	every: function(num, fun){

	 if (typeof fun != &quot;function&quot;){
		var nuevoArray = [];
		for (var i = 0; i &lt; this.length; i++) {
			if (i in this &amp;&amp; i%num == 0){
				nuevoArray.push(this[i]);
			}
		}
		return nuevoArray;
	 }
	 else{
		for (var i = 0; i &lt; this.length; i++) {
			if (i in this &amp;&amp; i%num == 0){
				fun.call(arguments[1], this[i], i);
			}
		}
	 }
	 
	return this;
	},
	
	randomize: function(){
		return ( Math.floor( Math.random() * ( this[1] - this[0] + 1 ) + ( this[0] ) ) );
	},
	
	random: function(){
		return this[[0, this.length - 1].randomize()];
	},
	
	mix: function(){
		var nuevoArray = [];
		while(nuevoArray.length != this.length){
			var rand = [0, this.length - 1].randomize();
			if( this[rand] != &quot;already taken&quot; ){
				nuevoArray.push( this[rand] );
				this[rand] = &quot;already taken&quot;;
			}
		}
		return nuevoArray;
	},
	
	range: function(){
		var nuevoArray = [];
		for(var n = this[0]; n &lt; this[1]; n++) nuevoArray[n]=n;
		return nuevoArray;
	},
	
	each: function(fun){
		for( var i in this ){
			if( !Array.prototype[i] ){
				fun.call(this, this[i], i);
			}
		}
	}
}, Array.prototype);
&lt;/code&gt;&lt;/code&gt;&lt;/pre&gt;

array.randomize:
&lt;code&gt;[5, 10].randomize() // devuelve un numero random entre 5 y 10&lt;/code&gt;

array.random:
&lt;code&gt;[1, 2, 3].random() // devuelve un valor random del array, que puede ser 1, 2 o 3&lt;/code&gt;

array.mix:
&lt;code&gt;[11, 22, 33].mix() // mezcla el array y devuelve por ejemplo 11, 33, 22&lt;/code&gt;

array.range:
&lt;code&gt;[5, 10].range() // devuelve un array con todos lo numeros entre 5 y 10 ( [5,6,7,8,9,10] )
[5, 10, 2].range() // equivale a [5, 10].range().every(2)&lt;/code&gt;

array.each:

&lt;code&gt;[11, 22, 33].each(function( valor, index ){
alert(valor); // alerta 11, 22 y 33
alert(index); // alerta 0, 1, 2
});&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>hice el metodo each y algunos mas:</p>
<pre><code>
extend({
	every: function(num, fun){

	 if (typeof fun != "function"){
		var nuevoArray = [];
		for (var i = 0; i < this.length; i++) {
			if (i in this &#038;&#038; i%num == 0){
				nuevoArray.push(this[i]);
			}
		}
		return nuevoArray;
	 }
	 else{
		for (var i = 0; i < this.length; i++) {
			if (i in this &#038;&#038; i%num == 0){
				fun.call(arguments[1], this[i], i);
			}
		}
	 }

	return this;
	},

	randomize: function(){
		return ( Math.floor( Math.random() * ( this[1] - this[0] + 1 ) + ( this[0] ) ) );
	},

	random: function(){
		return this[[0, this.length - 1].randomize()];
	},

	mix: function(){
		var nuevoArray = [];
		while(nuevoArray.length != this.length){
			var rand = [0, this.length - 1].randomize();
			if( this[rand] != "already taken" ){
				nuevoArray.push( this[rand] );
				this[rand] = "already taken";
			}
		}
		return nuevoArray;
	},

	range: function(){
		var nuevoArray = [];
		for(var n = this[0]; n < this[1]; n++) nuevoArray[n]=n;
		return nuevoArray;
	},

	each: function(fun){
		for( var i in this ){
			if( !Array.prototype[i] ){
				fun.call(this, this[i], i);
			}
		}
	}
}, Array.prototype);
</code></code></pre>
<p>array.randomize:<br />
<code>[5, 10].randomize() // devuelve un numero random entre 5 y 10</code></p>
<p>array.random:<br />
<code>[1, 2, 3].random() // devuelve un valor random del array, que puede ser 1, 2 o 3</code></p>
<p>array.mix:<br />
<code>[11, 22, 33].mix() // mezcla el array y devuelve por ejemplo 11, 33, 22</code></p>
<p>array.range:<br />
<code>[5, 10].range() // devuelve un array con todos lo numeros entre 5 y 10 ( [5,6,7,8,9,10] )<br />
[5, 10, 2].range() // equivale a [5, 10].range().every(2)</code></p>
<p>array.each:</p>
<p><code>[11, 22, 33].each(function( valor, index ){<br />
alert(valor); // alerta 11, 22 y 33<br />
alert(index); // alerta 0, 1, 2<br />
});</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>Por: gbt29</title>
		<link>http://www.anieto2k.com/2008/12/03/arrayevery-por-cada-elemento/#comment-52417</link>
		<dc:creator>gbt29</dc:creator>
		<pubDate>Wed, 03 Dec 2008 18:28:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.anieto2k.com/?p=6957#comment-52417</guid>
		<description>encontre un problema, cuando extendes la clase array y agregas metodos cuando haces un for in en un array te larga tambien los metodos agregados si es que el nombre de este no existe de forma nativa, osea una vez que extendiste y agregaste every

for( var i in [1, 2, 3] ){
	alert(i);
}
alerta 1, 2, 3, every

(solo en ie y los navegadores que no tiene every por defecto)

creo que la solucion va a ser extender array y agregar el metodo each que recorra cada uno y que se fije si no es un metodo de la clase array</description>
		<content:encoded><![CDATA[<p>encontre un problema, cuando extendes la clase array y agregas metodos cuando haces un for in en un array te larga tambien los metodos agregados si es que el nombre de este no existe de forma nativa, osea una vez que extendiste y agregaste every</p>
<p>for( var i in [1, 2, 3] ){<br />
	alert(i);<br />
}<br />
alerta 1, 2, 3, every</p>
<p>(solo en ie y los navegadores que no tiene every por defecto)</p>
<p>creo que la solucion va a ser extender array y agregar el metodo each que recorra cada uno y que se fije si no es un metodo de la clase array</p>
]]></content:encoded>
	</item>
	<item>
		<title>Por: aNieto2k</title>
		<link>http://www.anieto2k.com/2008/12/03/arrayevery-por-cada-elemento/#comment-52416</link>
		<dc:creator>aNieto2k</dc:creator>
		<pubDate>Wed, 03 Dec 2008 17:51:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.anieto2k.com/?p=6957#comment-52416</guid>
		<description>&lt;a href=&quot;#comment-52415&quot; title=&quot;Responder a gbt29&quot; rel=&quot;nofollow&quot;&gt;@gbt29&lt;/a&gt;: Buena idea, aunque la he podido reducir un poco.

&lt;pre&gt;&lt;code&gt;
extend({
       every: function(num, fun){
               var nuevoArray = [];
               for (var i = 0; i &lt; this.length; i++) {
                       if (i in this &amp;&amp; i%num == 0)
                               nuevoArray.push(this[i]);
			if (typeof fun == &#039;function&#039;)
					fun.call(arguments[1], this[i], i);
               }
               return (typeof fun == &#039;function&#039;) ? this : nuevoArray;
       }
}, Array.prototype);

&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p><a href="#comment-52415" title="Responder a gbt29" rel="nofollow">@gbt29</a>: Buena idea, aunque la he podido reducir un poco.</p>
<pre><code>
extend({
       every: function(num, fun){
               var nuevoArray = [];
               for (var i = 0; i &lt; this.length; i++) {
                       if (i in this &amp;&amp; i%num == 0)
                               nuevoArray.push(this[i]);
			if (typeof fun == 'function')
					fun.call(arguments[1], this[i], i);
               }
               return (typeof fun == 'function') ? this : nuevoArray;
       }
}, Array.prototype);

</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>Por: gbt29</title>
		<link>http://www.anieto2k.com/2008/12/03/arrayevery-por-cada-elemento/#comment-52415</link>
		<dc:creator>gbt29</dc:creator>
		<pubDate>Wed, 03 Dec 2008 17:23:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.anieto2k.com/?p=6957#comment-52415</guid>
		<description>tambien podrias hacer que si no le pasas una funcion te devuelva un nuevo array donde haya filtrado los elementos cada X, algo así:

&lt;pre&gt;&lt;code&gt;
extend({
	every: function(num, fun){

	 if (typeof fun != &quot;function&quot;){
		var nuevoArray = [];
		for (var i = 0; i &lt; this.length; i++) {
			if (i in this &amp;&amp; i%num == 0){
				nuevoArray.push(this[i]);
			}
		}
		return nuevoArray;
	 }
	 else{
		for (var i = 0; i &lt; this.length; i++) {
			if (i in this &amp;&amp; i%num == 0){
				fun.call(arguments[1], this[i], i);
			}
		}
	 }
	 
	return this;
	}
}, Array.prototype);
&lt;/code&gt;&lt;/pre&gt;
(no se si el tag code es el correcto)

ahora &lt;code&gt;[111,222,333,444,555,666].every(2)&lt;/code&gt; devolveria &lt;code&gt;[111,333,555]&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>tambien podrias hacer que si no le pasas una funcion te devuelva un nuevo array donde haya filtrado los elementos cada X, algo así:</p>
<pre><code>
extend({
	every: function(num, fun){

	 if (typeof fun != "function"){
		var nuevoArray = [];
		for (var i = 0; i &lt; this.length; i++) {
			if (i in this &amp;&amp; i%num == 0){
				nuevoArray.push(this[i]);
			}
		}
		return nuevoArray;
	 }
	 else{
		for (var i = 0; i &lt; this.length; i++) {
			if (i in this &amp;&amp; i%num == 0){
				fun.call(arguments[1], this[i], i);
			}
		}
	 }

	return this;
	}
}, Array.prototype);
</code></pre>
<p>(no se si el tag code es el correcto)</p>
<p>ahora <code>[111,222,333,444,555,666].every(2)</code> devolveria <code>[111,333,555]</code></p>
]]></content:encoded>
	</item>
</channel>
</rss>

