From a55b575e8089ee6cab7c5c262a7e6db55d0e34d6 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 14:46:50 +0100 Subject: unslug es: move --- .../string/localecompare/index.html | 159 --------------------- 1 file changed, 159 deletions(-) delete mode 100644 files/es/web/javascript/referencia/objetos_globales/string/localecompare/index.html (limited to 'files/es/web/javascript/referencia/objetos_globales/string/localecompare/index.html') diff --git a/files/es/web/javascript/referencia/objetos_globales/string/localecompare/index.html b/files/es/web/javascript/referencia/objetos_globales/string/localecompare/index.html deleted file mode 100644 index 2bda296c61..0000000000 --- a/files/es/web/javascript/referencia/objetos_globales/string/localecompare/index.html +++ /dev/null @@ -1,159 +0,0 @@ ---- -title: String.prototype.localeCompare() -slug: Web/JavaScript/Referencia/Objetos_globales/String/localeCompare -translation_of: Web/JavaScript/Reference/Global_Objects/String/localeCompare ---- -
{{JSRef}}
- -

El método localeCompare() devuelve un número que indica si la cadena de caracteres actual es anterior, posterior o igual a la cadena pasada como parámetro, en orden lexicográfico.

- -

Los nuevos argumentos locales y options permiten a las aplicaciones especificar el idioma y el orden de clasificación que debe usarse y personalizar el comportamiento de la función. En las implementaciones más antiguas, que ignoran los argumentos locales y options, la configuración locale y el orden de clasificación utilizados dependen enteramente de la implementación

- -

Sintaxis

- -
referenceStr.localeCompare(compareString[, locales[, options]])
- -

Parámetros

- -

Comprueba la sección Compatibilidad con el navegador para ver que navegadores soportan los argumentos locales y options, and the Checking for support for locales and options arguments for feature detection.

- -
-
compareString
-
La cadena con la que queremos comparar la cadena actual de caracteres.
-
- -
{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator', 'Parameters')}}
- -

Valor devuelto

- -

Un número negativo si la cadena de referencia ocurre antes de la cadena de comparación; positivo si la cadena de referencia ocurre después de la cadena de comparación; 0 si son equivalentes.

- -

Descripción

- -

Returns an integer indicating whether the referenceStr comes before, after or is equivalent to the compareStr.

- - - -

NO CONFIAR en que los valores devueltos sean siempre -1 o 1. Los resultados de enteros negativos y positivos varían entre los navegadores (así como entre diferentes versiones de un mismo navegador) porque la especificación W3C solo exige valores negativos y positivos. Algunos navegadores pueden devolver -2 o 2 o incluso algún otro valor negativo o positivo.

- -

Ejemplos

- -

Uso de localeCompare()

- -
// La letra "a" es anterior a la "c" produciendo un valor negativo
-'a'.localeCompare('c'); // -2 o -1 (u otro valor negativo)
-
-// Alfabeticamente la palabra "check" viene después de "against" produciendo un valor ppositivo
-'check'.localeCompare('against'); // 2 o 1 (u otro valor positivo)
-
-// "a" y "a" son equivalentes produciendo un valor neutro de 0
-'a'.localeCompare('a'); // 0
-
- -

Ordenar un array

- -

localeCompare enables a case-insensitive sort of an array.

- -
var items = ['réservé', 'premier', 'cliché', 'communiqué', 'café', 'adieu'];
-items.sort((a, b) => a.localeCompare(b)); // ['adieu', 'café', 'cliché', 'communiqué', 'premier', 'réservé']
-
- -

Verificar si el navegador soporta argumentos extendidos

- -

The locales and options arguments are not supported in all browsers yet. To check whether an implementation supports them, use the "i" argument (a requirement that illegal language tags are rejected) and look for a {{jsxref("RangeError")}} exception:

- -
function localeCompareSupportsLocales() {
-  try {
-    'foo'.localeCompare('bar', 'i');
-  } catch (e) {
-    return e.name === 'RangeError';
-  }
-  return false;
-}
-
- -

Uso de locales

- -

The results provided by localeCompare() vary between languages. In order to get the sort order of the language used in the user interface of your application, make sure to specify that language (and possibly some fallback languages) using the locales argument:

- -
console.log('ä'.localeCompare('z', 'de')); // a negative value: in German, ä sorts before z
-console.log('ä'.localeCompare('z', 'sv')); // a positive value: in Swedish, ä sorts after z
-
- -

Uso de options

- -

The results provided by localeCompare() can be customized using the options argument:

- -
// in German, ä has a as the base letter
-console.log('ä'.localeCompare('a', 'de', { sensitivity: 'base' })); // 0
-
-// in Swedish, ä and a are separate base letters
-console.log('ä'.localeCompare('a', 'sv', { sensitivity: 'base' })); // a positive value
-
- -

Performance

- -

When comparing large numbers of strings, such as in sorting large arrays, it is better to create an {{jsxref("Global_Objects/Collator", "Intl.Collator")}} object and use the function provided by its {{jsxref("Collator.prototype.compare", "compare")}} property.

- -

Especificaciones

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
EspecificaciónEstadoComentario
{{SpecName('ES3')}}{{Spec2('ES3')}}Definición inicial. Implementado en JavaScript 1.2.
{{SpecName('ES5.1', '#sec-15.5.4.9', 'String.prototype.localeCompare')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-string.prototype.localecompare', 'String.prototype.localeCompare')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-string.prototype.localecompare', 'String.prototype.localeCompare')}}{{Spec2('ESDraft')}} 
{{SpecName('ES Int 1.0', '#sec-13.1.1', 'String.prototype.localeCompare')}}{{Spec2('ES Int 1.0')}}Definiciones de los parámetros locale y option.
{{SpecName('ES Int 2.0', '#sec-13.1.1', 'String.prototype.localeCompare')}}{{Spec2('ES Int 2.0')}} 
{{SpecName('ES Int Draft', '#sec-String.prototype.localeCompare', 'String.prototype.localeCompare')}}{{Spec2('ES Int Draft')}} 
- -

Compatibilidad con el navegador

- - - -

{{Compat("javascript.builtins.String.localeCompare")}}

- -

Ver también

- - -- cgit v1.2.3-54-g00ecf