HISE Logo Forum
    • Categories
    • Register
    • Login

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

    Scheduled Pinned Locked Moved Bug Reports
    20 Posts 5 Posters 1.0k 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

      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

                                        22

                                        Online

                                        1.8k

                                        Users

                                        12.0k

                                        Topics

                                        104.4k

                                        Posts