Last active
August 15, 2020 04:35
-
-
Save eat-sleep-code/f7f19012b728a2a5725a740bdeb1319c to your computer and use it in GitHub Desktop.
Map String to Index
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
var mappingIndex = 0; | |
var mappingDictionary = []; | |
function MappingDictionary(stringToFind) { | |
output = 0; | |
var queryResult = mappingDictionary.filter(obj => Object.values(obj).some(val => val?val.toString().toLowerCase().includes(stringToFind):false))[0]; | |
if (queryResult) { | |
output = queryResult["Key"]; | |
} | |
else { | |
mappingIndex = mappingIndex + 1; | |
var mappingDictionaryEntry = {}; | |
mappingDictionaryEntry.Key = mappingIndex; | |
mappingDictionaryEntry.Value = stringToFind; | |
mappingDictionary.push(mappingDictionaryEntry); | |
output = mappingIndex; | |
} | |
console.log(stringToFind + ": " + output); | |
return output; | |
} | |
// var uniqueValue = inputIndex + "-" + inputValue; | |
//var output = MappingDictionary(uniqueValue); | |
MappingDictionary("dog"); | |
MappingDictionary("bird"); | |
MappingDictionary("cat"); | |
MappingDictionary("dog"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment