Forum

    • Register
    • Login
    • Search
    • Categories

    How to use sortWithFunction?

    Scripting Forum
    1
    2
    57
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • d.healey
      d.healey last edited by

      Tried this but it doesn't work, what's the correct usage?

      reg arr = [5, 3, 6, 4, 1, 2];
      
      Engine.sortWithFunction(arr, function(a, b)
      {
      	return a > b;
      });
      
      Console.print(trace(arr));
      

      Libre Wave - Freedom respecting instruments and effects
      My Patreon - HISE tutorials
      YouTube Channel - Public HISE tutorials

      d.healey 1 Reply Last reply Reply Quote 0
      • d.healey
        d.healey @d.healey last edited by d.healey

        @d-healey Two minutes digging around on the internet leads me to the solution

        reg arr = [5, 3, 6, 4, 1, 2];
        
        Engine.sortWithFunction(arr, function(a, b)
        {
            if (a < b) return -1 else return a > b;
        });
        
        Console.print(trace(arr));
        

        Libre Wave - Freedom respecting instruments and effects
        My Patreon - HISE tutorials
        YouTube Channel - Public HISE tutorials

        1 Reply Last reply Reply Quote 1
        • First post
          Last post

        23
        Online

        1.1k
        Users

        6.8k
        Topics

        62.4k
        Posts