Commits

Rui Vieira committed bed69c5

Current version is now written in CoffeeScript

Comments (0)

Files changed (2)

main/src/NATOtranslator.coffee

+words =
+        "a":"alfa",
+        "b":"bravo",
+        "c":"charlie",
+        "d":"delta",
+        "e":"echo",
+        "f":"foxtrot",
+        "g":"golf",
+        "h":"hotel",
+        "i":"india",
+        "j":"juliet",
+        "k":"kilo",
+        "l":"lima",
+        "m":"mike",
+        "n":"november",
+        "o":"oscar",
+        "p":"papa",
+        "q":"quebec",
+        "r":"romeo",
+        "s":"sierra",
+        "t":"tango",
+        "u":"uniform",
+        "v":"victor",
+        "w":"whiskey",
+        "y":"yankee",
+        "z":"zulu"
+
+char_to_nato  = (c) ->
+    chars = c.split("")
+    for char in chars
+        word = words[char]
+        if word is not undefined
+            return "#{word} "
+        else
+            return ""
+nato_to_char = (nato) ->
+    result = ""
+    words = nato.split(" ")
+    for word in words
+        result += word[0]
+    return result

main/src/NATOtranslator.js

-var NATOTranslator = {
-    words : {
-        "a":"alfa",
-        "b":"bravo",
-        "c":"charlie",
-        "d":"delta",
-        "e":"echo",
-        "f":"foxtrot",
-        "g":"golf",
-        "h":"hotel",
-        "i":"india",
-        "j":"juliet",
-        "k":"kilo",
-        "l":"lima",
-        "m":"mike",
-        "n":"november",
-        "o":"oscar",
-        "p":"papa",
-        "q":"quebec",
-        "r":"romeo",
-        "s":"sierra",
-        "t":"tango",
-        "u":"uniform",
-        "v":"victor",
-        "w":"whiskey",
-        "y":"yankee",
-        "z":"zulu"
-    },
-    char_to_nato : function(c) {
-        var result = "";
-        var chars = c.split("");
-        var number_of_chars = chars.length;
-        for (var i = 0; i < number_of_chars; ++i) {
-            var word = NATOTranslator.words[c[i]];
-            if (word != undefined) {
-                result = result + word + " ";
-            }
-        }
-        return result;
-    },
-    nato_to_char : function(nato) {
-        var result = "";
-        var words = nato.split(" ");
-        var number_of_words = words.length;
-        for (var i = 0; i < number_of_words; ++i) {
-            result = result + words[i].charAt(0);
-        }
-        return result;
-    }
-}