HISE Logo Forum
    • Categories
    • Register
    • Login

    Array.sort() doesn't work for string arrays

    Scheduled Pinned Locked Moved Bug Reports
    20 Posts 5 Posters 962 Views
    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.
    • Casey KolbC
      Casey Kolb
      last edited by

      Just noticed this bug. Array.sort() will only work on numbers and not strings. Can others confirm this happens in their HISE builds?

      var letters = ["d", "e", "c", "b", "a"];
      letters.sort();
      
      for (l in letters)
      	Console.print(l);
      // prints d e c b a
      
      var numbers = [3, 2, 1, 5, 4];
      numbers.sort();
      
      for (n in numbers)
      	Console.print(n);
      // prints 1 2 3 4 5
      

      Casey Kolb
      Founder & CEO of Lunacy Audio
      Composer | Producer | Software Developer

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

        I don't think it's a bug, but it would be nice to have it sort strings too.

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

        1 Reply Last reply Reply Quote 0
        • Casey KolbC
          Casey Kolb
          last edited by

          Based on the documentation it is: Array.sort()

          Casey Kolb
          Founder & CEO of Lunacy Audio
          Composer | Producer | Software Developer

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

            @Lunacy-Audio yep, you're right

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

            1 Reply Last reply Reply Quote 0
            • Casey KolbC
              Casey Kolb
              last edited by

              For the time being, I just pulled a string sort algorithm from the web for sorting string arrays. Works great for now 😀

              inline function sortStringArray(str) { 
                  local i = 0;
                  local j;
                  while (i < str.length) { 
                      j = i + 1; 
                      while (j < str.length) { 
                          if (str[j] < str[i]) { 
                              local temp = str[i]; 
                              str[i] = str[j]; 
                              str[j] = temp; 
                          } 
                          j++; 
                      } 
                      i++; 
                  } 
              } 
              

              Casey Kolb
              Founder & CEO of Lunacy Audio
              Composer | Producer | Software Developer

              1 Reply Last reply Reply Quote 1
              • ustkU
                ustk
                last edited by

                I've made a pull request after adding Array.sortNatural() API.
                It allows sorting strings, conventional numbers, strings containing numbers with a number priority, and objects (treated as string object name).
                You can also sort a mix of all the types

                Can't help pressing F5 in the forum...

                LindonL 1 Reply Last reply Reply Quote 1
                • LindonL
                  Lindon @ustk
                  last edited by

                  @ustk said in Array.sort() doesn't work for string arrays:

                  I've made a pull request after adding Array.sortNatural() API.
                  It allows sorting strings, conventional numbers, strings containing numbers with a number priority, and objects (treated as string object name).
                  You can also sort a mix of all the types

                  this never worked for me and still doesnt...

                  HISE Development for hire.
                  www.channelrobot.com

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

                    @Lindon I made a video about sorting arrays, might be of help

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

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

                      @d-healey said in Array.sort() doesn't work for string arrays:

                      @Lindon I made a video about sorting arrays, might be of help

                      oh I can sort array no problem - but it would be nice if this was available..

                      HISE Development for hire.
                      www.channelrobot.com

                      ustkU 1 Reply Last reply Reply Quote 0
                      • ustkU
                        ustk @Lindon
                        last edited by ustk

                        @Lindon Hmmm that's very strange because I am using currently everywhere in the current project and it works like a charm, at least for strings..

                        Although for objects, I've made a confusion and should've been more precise... It is not sorting json objects, but object reference names like Object 0x65de8a18 that are treated as string, which is of no use... 🙄

                        I make my own functions for sorting json, and it's just a real pain every single time... I wish there was a straight solution for this task...

                        Can't help pressing F5 in the forum...

                        LindonL 1 Reply Last reply Reply Quote 0
                        • LindonL
                          Lindon @ustk
                          last edited by

                          @ustk can you give me an example of your usage?

                          HISE Development for hire.
                          www.channelrobot.com

                          ustkU 1 Reply Last reply Reply Quote 0
                          • ustkU
                            ustk @Lindon
                            last edited by ustk

                            @Lindon

                            var stringArray = ["f", "a", "z"];
                            stringArray.sortNatural(); // ["a", "f", "z"]
                            

                            Can't help pressing F5 in the forum...

                            LindonL 1 Reply Last reply Reply Quote 0
                            • LindonL
                              Lindon @ustk
                              last edited by Lindon

                              @ustk hmm, yeah I get hanging update errors...dont worry about it I will continue with my home grown sort..

                              HISE Development for hire.
                              www.channelrobot.com

                              ustkU 1 Reply Last reply Reply Quote 0
                              • ustkU
                                ustk @Lindon
                                last edited by

                                @Lindon said in Array.sort() doesn't work for string arrays:

                                @ustk hmm, yeah I get hanging update errors...

                                what do you mean?

                                Can't help pressing F5 in the forum...

                                LindonL 1 Reply Last reply Reply Quote 0
                                • LindonL
                                  Lindon @ustk
                                  last edited by

                                  @ustk oh sorry wrong terms : here:

                                  MELODICSO1:! dangling listener

                                  HISE Development for hire.
                                  www.channelrobot.com

                                  ustkU d.healeyD 2 Replies Last reply Reply Quote 0
                                  • ustkU
                                    ustk @Lindon
                                    last edited by

                                    @Lindon You just buried me a bit more 🤣

                                    Can't help pressing F5 in the forum...

                                    LindonL 1 Reply Last reply Reply Quote 1
                                    • LindonL
                                      Lindon @ustk
                                      last edited by

                                      @ustk said in Array.sort() doesn't work for string arrays:

                                      @Lindon You just buried me a bit more 🤣

                                      yeah I think its just not cleaning up after itself correctly..

                                      HISE Development for hire.
                                      www.channelrobot.com

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

                                        @Lindon said in Array.sort() doesn't work for string arrays:

                                        @ustk oh sorry wrong terms : here:

                                        MELODICSO1:! dangling listener

                                        What are you drinking... :p

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

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

                                          @d-healey - the coolaid....

                                          HISE Development for hire.
                                          www.channelrobot.com

                                          1 Reply Last reply Reply Quote 1
                                          • NatanN
                                            Natan
                                            last edited by

                                            What is the Meaning of This?
                                            dangling listener

                                            It happens once I Check the plugin Parameters Names using Tools / Validate Plugin Parameters!

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

                                            50

                                            Online

                                            1.7k

                                            Users

                                            11.7k

                                            Topics

                                            101.8k

                                            Posts