Last active
December 30, 2015 01:48
-
-
Save le717/7757998 to your computer and use it in GitHub Desktop.
Match an acronym with it's full game name.
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
/* | |
Created 2013 Triangle717 | |
<http://Triangle717.WordPress.com/> | |
Please contact me at the address above if | |
you use this script in any of your work. :) | |
*/ | |
// Object containing the game names and acronyms | |
var gameNames = {"LR": "LEGO Racers", | |
"LR1": "LEGO Racers", | |
"LR2": "LEGO Racers 2", | |
"LRR": "LEGO Rock Raiders", | |
"DR": "Drome Racers", | |
"SR": "LEGO Stunt Rally", | |
"LL": "LEGO LEGOLAND", | |
"AT": "LEGO Alpha Team", | |
"LC": "LEGO Creator", | |
"LCKK": "LEGO Creator Knights Kingdom", | |
"LI": "LEGO Island", | |
"LI1": "LEGO Island", | |
"LI2": "LEGO Island 2", | |
"IXS": "Island Xtreme Stunts", | |
"RRU": "Rock Raiders United" | |
}; | |
function checkAcronym(text) { | |
/* Get the name of the game the acronym `text` stands for */ | |
// Remove all whitespace from the input | |
// FIXME: This would obviously be dropped if the code were to be implemented | |
text = text.replace(/\s/g, ""); | |
for (var arcro in gameNames) { | |
if (gameNames.hasOwnProperty(arcro)) { | |
// Convert text to uppercase for incase-sensitive-ness | |
if (text.toUpperCase() === arcro) { | |
// The user's text matches the acronym | |
// FIXME: Obviously this would be edited to display the hover-over tooltip for the fourm | |
console.log(gameNames[arcro]); | |
break; | |
} | |
} | |
} | |
}; | |
// This example would obviously be no good if the were to be implemented | |
checkAcronym("D R "); | |
checkAcronym("LR"); // returns LEGO Racers | |
checkAcronym("LR1"); // returns LEGO Racers | |
checkAcronym("LL"); // returns LEGO LEGOLAND | |
checkAcronym("IXS"); // returns Island Xtreme Stunts | |
checkAcronym("SR"); // returns Stunt Rally | |
checkAcronym("LR2"); // returns LEGO Racers 2 | |
// Proves the script is case-insenstive | |
checkAcronym("rru"); // returns Rock Raiders United |
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
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
Created 2013 Triangle717 | |
<http://Triangle717.WordPress.com/> | |
Please contact me at the address above if | |
you use this script in any of your work. :) | |
""" | |
from __future__ import print_function | |
# Dictionary containing the game names and acronyms | |
game_names = {("LR", "LR1"): "LEGO Racers", | |
"LR2": "LEGO Racers 2", | |
"LRR": "LEGO Rock Raiders", | |
"DR": "Drome Racers", | |
"SR": "LEGO Stunt Rally", | |
"LL": "LEGO LEGOLAND", | |
"AT": "LEGO Alpha Team", | |
"LC": "LEGO Creator", | |
"LCKK": "LEGO Creator Knights Kingdom", | |
"LI": "LEGO Island", | |
"LI1": "LEGO Island", | |
"LI2": "LEGO Island 2", | |
"IXS": "Island Xtreme Stunts", | |
"RRU": "Rock Raiders United" | |
} | |
def checkAcronym(text): | |
"""Get the name of the game the acronym `text` stands for""" | |
# Remove all whitespace from the input | |
# FIXME: This would obviously be dropped if the code were to be implemented | |
text = text.replace(" ", "") | |
for arcro in game_names.keys(): | |
# There is only one acronym for the game | |
if type(arcro) == str: | |
# Convert text to uppercase for case-insensitive-ness | |
if text.upper() == arcro: | |
# The user's text matches the acronym | |
print(game_names[arcro]) | |
break | |
# There are multiple acronyms for the game | |
else: | |
# The acronyms are stored in a tuple, an uneditable array | |
for multi_arcro in arcro: | |
# The user's text matches the acronym | |
if text.upper() == multi_arcro: | |
print(game_names[arcro]) | |
break | |
if __name__ == "__main__": | |
# This example would obviously be no good if the were to be implemented | |
checkAcronym("D R ") | |
checkAcronym("LR") # returns LEGO Racers | |
checkAcronym("LR1") # returns LEGO Racers | |
checkAcronym("LL") # returns LEGO LEGOLAND | |
checkAcronym("IXS") # returns Island Xtreme Stunts | |
checkAcronym("SR") # returns Stunt Rally | |
checkAcronym("LR2") # returns LEGO Racers 2 | |
# Proves the script is case-insenstive | |
checkAcronym("rru") # returns Rock Raiders United |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment