Facility Control

 View Only
  • 1.  Compare Strings in Dashboard Alphabetically?

    Posted 05-04-2023 12:58

    Hi,

    I'm looking for a way to compare two string alphabetically in Dashboard to then make some results happen based on the results. I am not much of a coder, but I have been learning a lot, and I've found that not ALL Java commands work in Dashboard.

    I'm trying to do a simple compare to prove the concept before building it into where I actually need it

    var a = "a";
    var b = "b";
    var c = a.compareTo(b);
    ogscript.debug(c);

    But I get the error "Cannot find function compareTo in object a" when I try it. 

    Is there another way to compare two strings and find out the alphabetical order of them?

    Thanks for any help



    ------------------------------
    Jake Lew
    Access Communications Co-Operative Limited
    ------------------------------


  • 2.  RE: Compare Strings in Dashboard Alphabetically?

    Posted 05-10-2023 19:20

    https://www.w3schools.com/js/js_array_sort.asp

    Soooo, you could Just add each to an array and then sort i? 



    ------------------------------
    Aleksander Stalsberg
    Inland Norway University of Applied Sciences/Lillehammer Icehockey Club
    Norway
    ------------------------------



  • 3.  RE: Compare Strings in Dashboard Alphabetically?

    Posted 05-11-2023 10:52

    Thanks Aleksander, I appreciate the response. However, as per what seems to be usual for me on these boards, I found the answer myself shortly after posting the message.

    "string.localeCompare(string2)" will return a 0 or 1 depending on the alphabetical value.

    I was using this to populate a Standings table for a league, pulling data from the web. The issue was that I was using the "rank" to set the data, but with some teams being tied for rank, it would set the first team data and then replace it with the second team data. So I added in some code to check if the rank is a duplicate, and then according to the alphabetical order of the team name, adjust the rank accordingly so when I set the data into the table all is good.



    ------------------------------
    Jake Lew
    Access Communications Co-Operative Limited
    ------------------------------



  • 4.  RE: Compare Strings in Dashboard Alphabetically?

    Posted 05-15-2023 07:34

    Ohh trust me I know that feeling. Lost count of how many times I've asked a question here, only to find a sollution myself 10 minutes later.

    For your case in point here though, I would really recommend looking into objects in javascript, how to use them, and also how to sort them on multiple key/value pairs in this.

    JS OBjects: https://www.w3schools.com/js/js_objects.asp
    Sorting example: https://levelup.gitconnected.com/sort-array-of-objects-by-two-properties-in-javascript-69234fa6f474

    We've all been new at some point! Glad you found a sollution, and more often than not, there's more than one way to the goal in coding! 



    ------------------------------
    Aleksander Stalsberg
    Inland Norway University of Applied Sciences/Lillehammer Icehockey Club
    Norway
    ------------------------------