<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dakoo &#187; Cosas raras de javascript</title>
	<atom:link href="http://www.dakoo.cl/category/cosas-raras-de-javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dakoo.cl</link>
	<description>¿Te gusta la web?</description>
	<lastBuildDate>Mon, 07 Jun 2010 13:40:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Comparacion de String con Javascript</title>
		<link>http://www.dakoo.cl/comparacion-de-string-con-javascript/</link>
		<comments>http://www.dakoo.cl/comparacion-de-string-con-javascript/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 03:26:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Cosas raras de javascript]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.dakoo.cl/?p=93</guid>
		<description><![CDATA[Una de las cosas raras que me ha pasado con js fue una comparación de string. Para los que han programado en otros lenguajes mas o menos  "modernos" saben que uno puede saber si un string es mayor que otro solo colocando la expresion "string1 &#62; strin2" o "string1 &#60; string2", esto en sí debería [...]]]></description>
			<content:encoded><![CDATA[<p>Una de las cosas raras que me ha pasado con js fue una comparación de string.</p>
<p>Para los que han programado en otros lenguajes mas o menos  "modernos" saben que uno puede saber si un string es mayor que otro solo colocando la expresion "string1 &gt; strin2" o "string1 &lt; string2", esto en sí debería devolver 1 o 0 dependiendo de los strings ingresados. Yo pensaba que esta "regla" también se respetaba para js, GRAN ERROR SEÑOR, osea, no es TAN error, porque como siempre hay excepciones a la regla.</p>
<p>En firefox me funcionaba, en chrome y en ie6 no.</p>
<p>Ahora la solución.</p>
<p>Cachureando por ahi y por alla, recordando funciones de otros lenguajes(java más especificamente)  llegue a una <a href="http://85.147.245.113/mirrorbooks/javascriptprofessional/4233final/LiB0017.html">página</a> en la que implementó  la función "compareTo", la cuál por ejemplo en java existe. Lo que hace esto es comparar caracter por caracter el unicode de cada uno y entregando el resultado. Con esto se dejan de lado los errores (que pienso que es donde se marean los navegadores) que se pueden producir por caracteres extraños, acentos por ejemplo, mayúsculas u otra cosa.</p>
<p>Vamos al código</p>
<div class="igBar"><span id="ljavascript-2"><a href="#" onclick="javascript:showPlainTxt('javascript-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JavaScript:</span>
<div id="javascript-2">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> compareTo<span style="color: #66cc66;">&#40;</span> s <span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #003366; font-weight: bold;">var</span> len1 = <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">length</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #003366; font-weight: bold;">var</span> len2 = s.<span style="color: #006600;">length</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #003366; font-weight: bold;">var</span> n = <span style="color: #66cc66;">&#40;</span> len1 &lt;len2 ? len1 : len2 <span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000066; font-weight: bold;">for</span><span style="color: #66cc66;">&#40;</span> i = <span style="color: #CC0000;color:#800000;">0</span> ; i &lt;n ; i++ <span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> a = <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">charCodeAt</span><span style="color: #66cc66;">&#40;</span> i <span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> b = s.<span style="color: #006600;">charCodeAt</span><span style="color: #66cc66;">&#40;</span> i <span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span> a != b <span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span><span style="color: #66cc66;">&#40;</span> a - b <span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #66cc66;">&#125;</span>&nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000066; font-weight: bold;">return</span><span style="color: #66cc66;">&#40;</span> len1 - len2 <span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">String.<span style="color: #006600;">prototype</span>.<span style="color: #006600;">compareTo</span> = compareTo; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Lindo no <img src='http://www.dakoo.cl/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Cualquier duda o sugerencia no dudes en comentar</p>
<p>Saludos tuto</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dakoo.cl/comparacion-de-string-con-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cosas raras de javascript</title>
		<link>http://www.dakoo.cl/cosas-raras-de-javascript/</link>
		<comments>http://www.dakoo.cl/cosas-raras-de-javascript/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 03:07:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Cosas raras de javascript]]></category>
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.dakoo.cl/?p=91</guid>
		<description><![CDATA[Son las 11 de la noche y recién pude resolver un error de js que me tuvo desde las 8 de la tarde. Es por esta razón y otras que he decidido crear esta categoría en este blog y documentarlar para que le sirvan a alguien que este "pasando" por lo mismo. Espero les sirva [...]]]></description>
			<content:encoded><![CDATA[<p>Son las 11 de la noche y recién pude resolver un error de js que me tuvo desde las 8 de la tarde. Es por esta razón y otras que he decidido crear esta categoría en este blog y documentarlar para que le sirvan a alguien que este "pasando" por lo mismo.</p>
<p>Espero les sirva y los disfruten <img src='http://www.dakoo.cl/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.dakoo.cl/cosas-raras-de-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->