From bdaaa5c58bc4c7009b321d8b97ae28a23e078f9d Mon Sep 17 00:00:00 2001 From: Zeno Popovici Date: Sun, 21 Aug 2016 15:21:24 +0300 Subject: [PATCH] #4 --- ...016-01-04-sorting-strings-with-accented-characters.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/_posts/en/javascript/2016-01-04-sorting-strings-with-accented-characters.md b/_posts/en/javascript/2016-01-04-sorting-strings-with-accented-characters.md index 9331f29d..6782346b 100644 --- a/_posts/en/javascript/2016-01-04-sorting-strings-with-accented-characters.md +++ b/_posts/en/javascript/2016-01-04-sorting-strings-with-accented-characters.md @@ -3,7 +3,7 @@ layout: post title: Sorting strings with accented characters tip-number: 04 -tip-username: loverajoel +tip-username: loverajoel tip-username-profile: https://github.com/loverajoel tip-tldr: Javascript has a native method **sort** that allows sorting arrays. Doing a simple `array.sort()` will treat each array entry as a string and sort it alphabetically. But when you try order an array of non ASCII characters you will obtain a strange result. tip-writer-support: https://www.coinbase.com/loverajoel @@ -68,4 +68,9 @@ Fortunately, there are two ways to overcome this behavior [localeCompare](https: - For each method you can customize the location. - According to [Firefox](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#Performance) Intl.Collator is faster when comparing large numbers of strings. -So when you are working with arrays of strings in a language other than English, remember to use this method to avoid unexpected sorting. \ No newline at end of file +So when you are working with arrays of strings in a language other than English, remember to use this method to avoid unexpected sorting. + +## Playground +
+ JSTips.co - Sorting strings with accented characters on jsbin.com +