• I have refactored some code to save memory using Typed Arrays and have come in to a problem which I have managed to replicate using the following code:

    x=new Uint32Array([30474260, 124846100, 219217940, 313589780, 407961620, 502333460, 596705300, 33423370, 127795210, 222167050, 316538890, 410910730, 505282570, 599654410, 49152018, 143523858, 237895698, 332267538, 426639378, 521011218, 615383058, 53084170, 147456010, 241827850, 336199690, 430571530, 524943370, 619315210, 64880661, 159252501, 253624341, 347996181, 442368021, 536739861, 631111701, 86507535, 180879375, 275251215, 369623055, 463994895, 558366735, 652738575]);
    
    console.log(x);
    
    x.sort(function(a, b){return (a - b);});
    
    console.log(x);
    

    I get the following Output for the second console.log (the first is as expected):

    new Uint32Array([30474260, 33423370, 49152018, 124846100, 53084170, 124846100, 124846100, 64880661, 124846100, 86507535, 124846100, 143523858, 147456010, 237895698, 407961620, 407961620, 241827850, 407961620, 336199690, 407961620, 407961620, 127795210, 407961620, 159252501, 407961620, 253624341, 410910730, 316538890, 410910730, 180879375, 410910730, 410910730, 410910730, 442368021, 442368021, 410910730, 442368021, 369623055, 410910730, 0, 410910730, 0])
    

    As you can see its a bit of a mess - some values missing, others repeated.

    I haven't exceeded the maximum value for a Uint32 ( 4,294,967,295).

    Any ideas?

About

Avatar for DaveNI @DaveNI started