home.social

#javascriptshit — Public Fediverse posts

Live and recent posts from across the Fediverse tagged #javascriptshit, aggregated by home.social.

  1. Javascript is so sucky sometimes.

    const array1 = [1, 30, 4, 21, 100000];
    array1.sort();
    console.log(array1);
    // output: Array [1, 100000, 21, 30, 4]

    const array2 = [1, 30, 4, 21, 100000];
    array2.sort((a,b)=>a-b);
    console.log(array2);
    // output: Array [1, 4, 21, 30, 100000]

    I know that by default it sorts alphabetically, but WHY?! I'M GIVING YOU NUMBERS, SORT NUMERICALLY!

    #javascript #JavaScriptShit #makesnosense