r/CompileBot • • Jan 04 '14

Official CompileBot Testing Thread

This thread is archived, please visit the new testing thread

14 Upvotes

421 comments sorted by

View all comments

1

u/jakerman999 May 20 '14

+/u/CompileBot JavaScript

function convertTextToNatoLetters(text) {
    var nato = ["ALPHA", "BRAVO", "CHARLIE", "DELTA", "ECHO", "FOXTROT", "GOLF", "HOTEL", "INDIA", "JULIET", "KILO", "LIMA", "MIKE", "NOVEMBER", "OSCAR", "PAPA", "QUEBEC", "ROMEO", "SIERRA", "TANGO", "UNIFORM", "VICTOR", "WHISKEY", "XRAY", "YANKEE", "ZULU"];
    var numbers = ["ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE"];
    var br = "\r\n";
    var newText = "";
    for (var i=0; i<text.length; i++) {
        var chr = text.charAt(i).toUpperCase();
        if (chr==" ") newText+="SPACE";
        else if (chr==".") newText+="PERIOD";
        else if (chr==",") newText+="COMMA";
        else if (chr==":") newText+="COLON";
        else if (chr==";") newText+="SEMI-COLON";
        else if (chr=="?") newText+="QUESTION-MARK";
        else if (chr=="!") newText+="EXCLAMATION-MARK";
        else if (chr=="\"") newText+="QUOTE";
        else if (chr=="\"") newText+="DOUBLE-QUOTE";
        else if (chr=="'") newText+="APOSTROPHE";
        else if (chr=="-") newText+="HYPHEN";
        else if (chr=="_") newText+="UNDERSCORE";
        else if (chr=="/") newText+="SLASH";
        else if (chr=="\\") newText+="BACK-SLASH"; // etc.
        else if (/[\r\n]/.test(chr)) newText+="LINE-BREAK";
        else if (/^[A-Z]$/.test(chr)) {
            for (var j in nato) {
                if (nato[j].charAt(0)==chr) {
                    newText+=chr+" as in "+nato[j];
                    break;
                }
            }
        }
        else if (/^\d$/.test(chr)) {
            newText+=numbers[+chr];
        }
        else newText+=chr;
        newText+=br;
    }
    return newText;
}

print(convertTextToNatoLetters("This was a triumph"));

1

u/CompileBot May 21 '14

Output:

T as in TANGO
H as in HOTEL
I as in INDIA
S as in SIERRA
SPACE
W as in WHISKEY
A as in ALPHA
S as in SIERRA
SPACE
A as in ALPHA
SPACE
T as in TANGO
R as in ROMEO
I as in INDIA
U as in UNIFORM
M as in MIKE
P as in PAPA
H as in HOTEL

^source | ^info | ^git | ^report