• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

[WebDialog] A-H, I-M, N-Z in Javascript

Scheduled Pinned Locked Moved Developers' Forum
9 Posts 2 Posters 185 Views 2 Watching
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.
  • C Offline
    chrisglasier
    last edited by 13 Nov 2009, 04:52

    Can anyone help with an easy way to separate a 1000+ element array into alphabetical chunks as in the caption. First letters are both upper and lower case and there are also special characters. The last can be chucked into a "remainder" array I suppose.

    Any help much appreciated!

    Chris

    With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 13 Nov 2009, 07:55

      Untested.

      
      // assuming variable arr with the values we deal with
      var ah = new Array()
      var im = new Array()
      var nz = new Array()
      var others = new Array()
      arr.sort()
      for (value in arr)
      {
        switch(value.charAt(0))
        {
        case 'a';
        case 'b';
        case 'c';
        case 'd';
        case 'e';
        case 'f';
        case 'g';
        case 'h';
          ah.push(value)
          break;
        case 'i';
        case 'j';
        case 'k';
        case 'l';
        case 'm';
          im.push(value)
          break;
        case 'n';
        case 'o';
        case 'p';
        case 'q';
        case 'r';
        case 's';
        case 't';
        case 'u';
        case 'v';
        case 'w';
        case 'x';
        case 'y';
        case 'z';
          nz.push(value)
          break;
        default;
          others.push(value)
        }
      }
      
      

      Thomas Thomassen — SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • C Offline
        chrisglasier
        last edited by 13 Nov 2009, 08:00

        @thomthom said:

        Untested.

        About to be! Thanks, will let you know when successful.

        I need to add value.charAt(0).toLowerCase() I guess.

        Positively

        Chris

        With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

        1 Reply Last reply Reply Quote 0
        • T Offline
          thomthom
          last edited by 13 Nov 2009, 08:26

          @chrisglasier said:

          I need to add value.charAt(0).toLowerCase() I guess.

          Yes! I forgot about that!

          Thomas Thomassen — SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • T Offline
            thomthom
            last edited by 13 Nov 2009, 08:26

            I wonder if javascripts sorting deals with unicode... wonder if it puts the norwegian æøå after z....

            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • C Offline
              chrisglasier
              last edited by 13 Nov 2009, 09:15

              Sorry Thom I cannot get it to work yet. Can you spot anything silly in this code or guide me how to test "your bit." Takk

              function apimMethodsAll(sl,xx){
              	//lists unique method names sl not used here; xx = "ah" and other labels
              	var list = new Array();
              	for (n in nset) {
              		nn = n.split(".");
              		if(nn[0] > 10) continue;
              		//cut as sample for testing - contains good range
              		if(nn.length == 2){
              			thisName = window.nset[n].name;
              			list.push(new Array(thisName,n));
              		}
              	}
              	list.sort();
              	//list tests OK
              	var lastName = null;
              	var unique = new Array();
              	for(a=0; a<list.length; a++){
              		if (list[a][0] != lastName){
              			unique.push(list[a][1]);
              		}
              	lastName = list[a][0];
              	}
              	//unique tests OK
              	var ah = new Array()
              	var im = new Array()
              	var nz = new Array()
              	var spec = new Array()
              	for (value in unique){
              		switch(value.charAt(0).toLowerCase()){
              			case 'a'; 
              			case 'b';
              			case 'c';
              			case 'd';
              			case 'e';
              			case 'f';
              			case 'g';
              			case 'h';
              			ah.push(value)
              			break;
              			case 'i';
              			case 'j';
              			case 'k';
              			case 'l';
              			case 'm';
              			im.push(value)
              			break;
              			case 'n';
              			case 'o';
              			case 'p';
              			case 'q';
              			case 'r';
              			case 's';
              			case 't';
              			case 'u';
              			case 'v';
              			case 'w';
              			case 'x';
              			case 'y';
              			case 'z';
              			nz.push(value)
              			break;
              			default;
              			spec.push(value)
              		}	
              	}
              	//tested alert(ah) blank
                	list = eval(xx)
              	//list blank
              	coreSliderList(list,0);
              	//Doms the list
              }
              

              With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

              1 Reply Last reply Reply Quote 0
              • C Offline
                chrisglasier
                last edited by 13 Nov 2009, 09:24

                apimNov 13.png

                A snap of the result of running unique array rather than list in the code above

                With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

                1 Reply Last reply Reply Quote 0
                • C Offline
                  chrisglasier
                  last edited by 13 Nov 2009, 09:41

                  Sorry just by sending the last stuff I think I have found the answer. Can I get back to you. Takk

                  With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

                  1 Reply Last reply Reply Quote 0
                  • C Offline
                    chrisglasier
                    last edited by 13 Nov 2009, 15:27

                    I discussed this with Jim just now and we decided that it is better to include the full methods output for the beta version so interested parties can understand and improve the code holistically. But thanks for your help. Sometimes I'm a little too quick off the mark!

                    Chris

                    With TBA interfaces we can analyse what is to be achieved so that IT can help with automation to achieve it.

                    1 Reply Last reply Reply Quote 0
                    • 1 / 1
                    1 / 1
                    • First post
                      1/9
                      Last post
                    Buy SketchPlus
                    Buy SUbD
                    Buy WrapR
                    Buy eBook
                    Buy Modelur
                    Buy Vertex Tools
                    Buy SketchCuisine
                    Buy FormFonts

                    Advertisement