10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-11-03 20:53:59 +01:00

Fix uniq function

This commit is contained in:
Anthony Scemama 2020-12-01 23:52:53 +01:00
parent 057146838f
commit 721d95b4d0

View File

@ -1,11 +1,11 @@
function uniq(array)
{
if (array.length == 0) return [];
const sortedArray = array.sort().map( x => [x, JSON.stringify(x)] );
var uniqueArray = [ sortedArray[0][0] ];
const sortedArray = array.map( x => [JSON.stringify(x), x] ).sort();
var uniqueArray = [ sortedArray[0][1] ];
for (let i=1 ; i<sortedArray.length ; i++) {
if ( sortedArray[i][1] != sortedArray[i-1][1])
uniqueArray.push(sortedArray[i][0])
if ( sortedArray[i][0].localeCompare(sortedArray[i-1][0]) != 0 )
uniqueArray.push(sortedArray[i][1])
}
return uniqueArray;
}