-
-
Save kunalbhatt/acf097eb0a723781db92 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Represent a small bilingual lexicon as a Javascript object in the following fashion {"merry":"god", "christmas":"jul", "and":"och", "happy":gott", "new":"nytt", "year":"år"} and use it to translate your Christmas cards from English into Swedish. | |
| var greetings = { | |
| "merry": "god", | |
| "christmas": "jul", | |
| "and": "och", | |
| "happy": "gott", | |
| "new": "nytt", | |
| "year": "ar" | |
| }; | |
| var swedish = ""; | |
| function translate(phase) { | |
| for (var name in greetings) { | |
| if (greetings.hasOwnProperty(name)) { | |
| var sentence = phase.split(/\s/); | |
| for (var i = 0; i <= sentence.length; i++) { | |
| if (sentence[i] === name) { | |
| swedish += greetings[name] + " "; | |
| } | |
| } | |
| } | |
| } | |
| swedish = swedish.trim(); | |
| swedish = swedish += "!"; | |
| return swedish[0].toUpperCase() + swedish.slice(1); | |
| } | |
| console.log(translate("merry christmas and happy new year")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment