Let's make a basic list and sort it to make sure that 2
is ALWAYS first in the list. Simple enough, right?
[1, 2, 3].sort((a, b) => {
if (a === 2) return -1;
return 0;
});
Chrome result: ✓
[2, 1, 3]
Node result: X
[1, 2, 3]
In order to get this behaviour in Node, you could - weirdly enough - look at the b
parameter and make it return 1 if it's 2
:
[1, 2, 3].sort((a, b) => {
if (b === 2) return 1;
return 0;
});
With this implementation you get the opposite result; Chrome will be [1, 2, 3] and Node will be [2, 1, 3].
Do you have a logical explaination for this behaviour? Is my sorting function conceptually flawed? If so, how would you write this sorting behaviour?
I need to handle multiple event which will generate same HTML dynamically. I have added addEventListener for all elements. Also getting different event value. Now i just need to set this result to ...
I need to handle multiple event which will generate same HTML dynamically. I have added addEventListener for all elements. Also getting different event value. Now i just need to set this result to ...
Following scenario/my solution consists of the following: Project one: (SELF HOST) I have a SignalR console application which handles the logic including the authentication process ( queries ...
Following scenario/my solution consists of the following: Project one: (SELF HOST) I have a SignalR console application which handles the logic including the authentication process ( queries ...
I'm trying to solve the task, get quantity of missed elements from an array. For example, if given an array [1,3,6], the quantity of missed elements is 3 (2,4,5). But somewhere code goes wrong and ...
I'm trying to solve the task, get quantity of missed elements from an array. For example, if given an array [1,3,6], the quantity of missed elements is 3 (2,4,5). But somewhere code goes wrong and ...
I make a node js web app for generating report. My idea is to use .jasper file (jasper report) to generate these reports. I've tried a bunch of node js library to do this, but nothing seems to work. ...
I make a node js web app for generating report. My idea is to use .jasper file (jasper report) to generate these reports. I've tried a bunch of node js library to do this, but nothing seems to work. ...