Is there a column-type to convert an array of A-Z to an array of 1-26 (position in the alphabet)?

Hi!
For an ice-breaker, I’d like each member to learn how to spell his/her name in International Aeronautical Code. You know “Alpha, Tango, Charlie”. So I can help him/her by displaying it. Or even Morse Code.
Example for L-Y-M-E-I
Lima-Yankee-Mike-Echo-India

J-E-F-F
Juliet-Echo-FoxTrot-FoxTrot

funny, @Jeff_Hager: a typical US dance :man_dancing::dancer:

D-A-R-R-E-N
Delta-Alpha-Romeo-Romeo-Echo-November
Don’t tell me your car happens to be an Alpha-Romeo. Or that you used to work for / fly on Delta Airlines

Is there a column-type/plugin to
convert an array to another
or
convert each letter by its position in the alphabet (so an item from array 1 to another from array 2 same position)

or do I have to compute it myself?
Thks :cherry_blossom:


1 Like

I don’t think any of the existing plugins will do it, but it wouldn’t be too difficult to write one.

I started having a play to see how far I could get without writing any code.

Not very :joy:

I might come back to this later…

4 Likes

:grinning_face_with_smiling_eyes: Maybe there’s an existing code that we can just integrate like </> snippet to let even anonymous users play with?
I know a “Shakespearien insult generator” or a “Tintin Captain Haddock (in French) insults generator”.
Sometimes they can be integrated in the web site, don’t know if it’s allowed in Glide apps. The only pb can be the “raw design”.
OK, have fun, Delta-Alpha-Romeo-Romeo-November :compass:
BTW, my Name anagram could be EMILY
I’d start by creating an array with the 26 letters to search in. And the 26 international codes.
Then split the user name and go into each letter position in array 1 to retrieve the international match in array 2.
If there’s a shortcut, or an existing plugin to insert in the app, anyone is welcome to say.

This will work in a Javascript Code column. Just copy and paste into the code section.

Here is a copyable app that uses it https://alpha-words.glideapp.io/

Enjoy!

function alphaWord(text) {

  let alphaWord = ["Alpha", "Bravo", "Charlie", "Delta", "Echo",
  "Foxtrot", "Golf", "Hotel", "India", "Juliet", "Kilo", "Lima",
  "Mike", "November", "Oscar", "Papa", "Quebec", "Romeo", "Sierra",
  "Tango", "Uniform", "Victor", "Whiskey", "X-ray", "Yankee", "Zulu"]
  let result = '';
  text = text.toUpperCase();
  let unicodeNum;
  
  for (var i = 0; i < text.length; i++){
    unicodeNum = text.charCodeAt(i) - 65;
    if ((unicodeNum > -1) && (unicodeNum < 26)) {
      result += alphaWord[unicodeNum] + " ";
    } else {
      result += "- ";
    }
  }
  
  return result

}
return alphaWord(p1);
8 Likes

Thks so much, George. I didn’t think JS was required for this. Good thing I ask first!
I didn’t even plan to add this feature so quickly, but now I’ll have to😄, c’est malin !
I just need to think of a nice way to maybe prompt for any other name than the current user’s, to let him/her play with and learn. Maybe just a text entry field and a button to trigger the conversion.
EDIT: Just did it. Everything’s fine :ok:
Very unexpectedly helpful. Hope you enjoyed it, George :cherry_blossom::croissant::teddy_bear:
I mean Golf-Echo-Oscar-Romeo-Golf-Echo
:blush::compass::ship:

1 Like

Sorry if I reopen the topic for a little while, to adjust the code before checking again the Solution.
1/remove the “-” for the last alpha code: it would be better to append a new item to the resulting table than to add a string to a resulting string. Getting a resulting table from the alpha table is more open to any management like separators.
I should be able to replace this part of JS with an append in array. Though I’m not good at object languages like JS, but at “old school” Pascal & Basic.

2/a little issue with “long names” and Glide text fields (even the smallest or footnote)



I can save the two split and join column if the separator is directly inside the JS
I chose “/” for composed first names
Marie-Caroline is not very long, but it’s truncated in display.
I added a new line to separate Marie and Caroline with result += ‘\n’;
I also added a Remove Accents Column otherwise it’s not converted (and not sure how it works with other languages like Vietnamese names @ThinhDinh image
The Hint component cannot manage that with too big font size

image

Looks good. Hint, when posting code if you surround the text with three ticks (upper left next to the 1 on most keyboards). Use them like you would quotes but 3 ticks on each side. I usually put them on the preceeding line and the following line. Then you end up with copy and pastable code making it easier for others to use.

3 Likes

@L.M I made a small change to the code that handles those diacritics or accents inside the function so the extra column you added is not needed.

function alphaWord(text) {
  // set up the replacement array
  let alphaWord = ["Alpha", "Bravo", "Charlie", "Delta", "Echo",
  "Foxtrot", "Golf", "Hotel", "India", "Juliet", "Kilo", "Lima",
  "Mike", "November", "Oscar", "Papa", "Quebec", "Romeo", "Sierra",
  "Tango", "Uniform", "Victor", "Whiskey", "X-ray", "Yankee", "Zulu"]
  let result = '';
  
  // replace graphemes and diacritics. Credit to https://stackoverflow.com/a/37511463/1899661
  text = text.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
  // convert to uppercase
  text = text.toUpperCase();
  let unicodeNum;
  
  for (var i = 0; i < text.length; i++){
    unicodeNum = text.charCodeAt(i) - 65;
    if ((unicodeNum > -1) && (unicodeNum < 26)) {
      result += alphaWord[unicodeNum] + " ";
    } else {
      result += "- ";
    }
  }
  
  return result

}

return alphaWord(p1)
5 Likes

Thks, George :slight_smile:
BTW, I keep on getting this bug


It doesn’t trouble the result, but, sth doesn’t agree with Glide

Just changed the code to trim and replace spaces by point (for a more “code look”).
The hyphen “-” is not necessary for the “code look”. I don’t think it is spelled on radio communications :blush:
I’ll just warn that the code cannot work with all special characters like Russian or some Vietnamese ones: it’s still supposed to be a code name, so.

function alphaWord(text) {
  // set up the replacement array
  let alphaWord = ["Alpha", "Bravo", "Charlie", "Delta", "Echo",
  "Foxtrot", "Golf", "Hotel", "India", "Juliet", "Kilo", "Lima",
  "Mike", "November", "Oscar", "Papa", "Quebec", "Romeo", "Sierra",
  "Tango", "Uniform", "Victor", "Whiskey", "X-ray", "Yankee", "Zulu"]
  let result = '';
  
  // replace graphemes and diacritics. Credit to https://stackoverflow.com/a/37511463/1899661
  text = text.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
  // convert to uppercase
  text = text.toUpperCase();
  let unicodeNum;
  
  for (var i = 0; i < text.length; i++){
    unicodeNum = text.charCodeAt(i) - 65;
    if ((unicodeNum > -1) && (unicodeNum < 26)) {
      result += alphaWord[unicodeNum] + " ";
    } else {
      result += "";
    }
  }
  
  return result.trim().replace(/ /g, '·')

}

return alphaWord(p1)

I can close this topic. Thks so much, George.
I’ll look at your other JS about Relative Time asap.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.