Last active
April 2, 2020 17:12
-
-
Save ellockie/ecc4fe404df023c503ab00094cc1e46b to your computer and use it in GitHub Desktop.
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
// the generator singleton | |
const generatorSingleton = (() => { | |
function getUniqueInstance() { | |
if (!instance) { | |
instance = this.getLetterRepresenations(); | |
} | |
return instance; | |
} | |
let instance = null; | |
return {getUniqueInstance}; | |
})(); | |
// art reverse-mapper | |
function getLetterFromArt(representation) { | |
const generatorInstance = generatorSingleton.getUniqueInstance.bind(this)(); | |
return generatorInstance[representation] ? generatorInstance[representation] : '?'; | |
} | |
// approximates the testing environment | |
function runTestingEnv() { | |
// hidden function | |
this.getLetterRepresenations = () => { | |
console.log('G E N E R A T I N G L E T T E R S...'); | |
const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; | |
const representations = {}; | |
letters.split('') | |
// reverse-mapped 'art' representation | |
.map(letter => representations[letter + letter + letter] = letter); | |
return representations; | |
} | |
console.log(getLetterFromArt.call(this, 'AAA')); // G E N E R A T I N G L E T T E R S... | |
// A | |
console.log(getLetterFromArt.call(this, 'BBB')); // B | |
console.log(getLetterFromArt.call(this, 'XXX')); // X | |
console.log(getLetterFromArt.call(this, 'Who am I?')); // ? | |
} | |
runTestingEnv(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment