Skip to content

Instantly share code, notes, and snippets.

@kosalvann
Created September 25, 2015 03:06
Show Gist options
  • Save kosalvann/2a33b36c640a5297235a to your computer and use it in GitHub Desktop.
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.
// 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