0
0

More than 1 year has passed since last update.

<JavaScript> Memo: A Function to Order Amateur Radio Callsigns According to JARL Bureau's Rule

Last updated at Posted at 2023-02-04

Goal

To issue QSL cards (contact confirmation cards) to amateur radio stations, we need to sort them according to a certain rule defined by JARL (Japan Amateur Radio League):

I wrote a function to obtain sorting keys from callsigns for this purpose.

Code

JavaScript

const JACallSignRegex = /^(?<prefix>J[A-S]|7[J-N]|8[J-N])(?<area>\d)(?<suffix>[0-9A-Za-z]+)(?:\/(?<modifier>.+))?$/i;

function JARLBureauOrderKey(callSign){

    let resultKey = "";

    if(JACallSignRegex.test(callSign)){
        let callSignMatch = callSign.match(JACallSignRegex);
        switch(callSignMatch.groups.prefix[0]){
            case "J":
                resultKey = "1" 
                        + ((parseInt(callSignMatch.groups.area) - 1 + 10)% 10 + 1).toString(16)
                        + callSignMatch.groups.prefix
                        + callSignMatch.groups.suffix.length
                        + callSignMatch.groups.suffix;
                break;

            case "7":
                resultKey = "7"
                        + callSignMatch.groups.prefix
                        + ((parseInt(callSignMatch.groups.area) - 1 + 10)% 10 + 1).toString(16)
                        + callSignMatch.groups.suffix;

                break;

            case "8":
                resultKey = "8"
                        + callSignMatch.groups.prefix
                        + ((parseInt(callSignMatch.groups.area) - 1 + 10)% 10 + 1).toString(16)
                        + callSignMatch.groups.suffix;

                break;

            default:
                resultKey = "0" + callSign
        }
    }
    else{
        resultKey = "0" + callSign
    }

    return resultKey;
}
 

Example

In the ASCII order,...

[Callsign]       [Key]
7J1xxx     ->   77J3xxx
7N1xxx     ->   77N1xxx
7N4xxx     ->   77N4xxx
8J0x       ->   88Jax
8N2xxxx    ->   88N2xxxx
JA0xxx     ->   1aJA3xxx
JA1AAA     ->   11JA3AAA
JA1QQ      ->   11JA2QQ
JA2AA      ->   12JA2AA
JR1xxx     ->   11JR3xxx
JR2xxx     ->   12JR3xxx
JR3xxx     ->   13JR3xxx

("x" stands for an arbitrary alphabet)

These should be ordered as

JA1QQ
JA1AAA
JR1xxx
JA2AA
JR2xxx
JR3xxx
JA0xxx
7J1xxx
7N1xxx
7N4xxx
8J0x
8N2xxxx

and so are they by using the key.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0