Created
September 25, 2015 03:06
-
-
Save kosalvann/2a33b36c640a5297235a to your computer and use it in GitHub Desktop.
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.
This file contains 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. | |
// https://jsfiddle.net/phd824xh/ | |
// Capitalise each word | |
function capitalise(string) { | |
return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase(); | |
} | |
// Show keys, values from array | |
function showObjectArray(obj) { | |
var results = ""; | |
for (var prop in obj) { | |
if (obj.hasOwnProperty(prop)){ | |
// results += capitalise(prop) + " "; | |
results += capitalise(prop) + " (" + capitalise(obj[prop]) + ") "; | |
} | |
} | |
return results; | |
} | |
// Words to translate | |
var words = { | |
"merry": "god", | |
"christmas": "jul", | |
"and": "och", | |
"happy": "gott", | |
"new": "nytt", | |
"year": "år" | |
}; | |
// Print to screen | |
console.log(showObjectArray(words)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment