0

I have the same arrays with strings, but they it array does not sort correctly and it is copied from my pc. items is typed in the browser.

https://jsfiddle.net/acc8xf0g/

var items = ["hard", "intermediate", "easy"];

var it = [
  "intermediate",
  "hard",
  "еasy"
];

items.sort(function(a, b) {
  return a.localeCompare(b);
});

it.sort(function(a, b) {
  return a.localeCompare(b);
})

$("#test").html(items.join(" "));
$("#test2").html(it.join(" "));
1
  • It's not actually the same array. Where did you get the 2nd array from? Commented Dec 18, 2015 at 19:04

2 Answers 2

5

That is not an ascii e in "еasy" (in your it array).

It is a Cyrillic е: http://www.fileformat.info/info/unicode/char/0435/index.htm

Just delete the 'e' and type it again normally.

Updated fiddle: https://jsfiddle.net/acc8xf0g/2/

Sign up to request clarification or add additional context in comments.

Comments

3

Look at the actual hex value of the "e" in the it array:

22 68 61 72 64 22 2c 20  22 69 6e 74 65 72 6d 65  |"hard", "interme|
64 69 61 74 65 22 2c 22  65 61 73 79 22 0a        |diate","easy".|


22 69 6e 74 65 72 6d 65  64 69 61 74 65 22 2c 20  |"intermediate", |
22 68 61 72 64 22 2c 20  22 d0 b5 61 73 79 22 0a  |"hard", "..asy".|

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.