Last active
September 10, 2020 19:15
-
-
Save hartzis/54e1ff87a08fbb463b0483f02850e9df to your computer and use it in GitHub Desktop.
Set and Map lookup example
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
const interestSurcharge = new Set(['AL']); | |
const flagshipOriginationFee = new Set(['AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DE', 'DC', 'FL', 'GA', 'HI', | |
'ID', 'IA', 'KS', 'KY', 'LA', 'ME', 'MS', 'MO', 'NM', 'ND', 'OH', 'OR', | |
'RI', 'SC', 'SD', 'UT', 'VA', 'WV', 'WI', 'WY']); | |
const documentPreparation = new Set(['IL']); | |
const nonrefundablePrepaidFinanceCharge = new Set(['IN']); | |
const notApplicable = new Set(['MD', 'MA', 'MN', 'MT', 'NV', 'NH', 'NJ', 'NY', 'NC', 'PA', 'VT']); | |
| |
const feeNameMap = new Map([ | |
[flagshipOriginationFee, 'Flagship Origination Fee'], | |
[interestSurcharge, 'Interest Surcharge'], | |
[documentPreparation, 'Document Preparation'], | |
[nonrefundablePrepaidFinanceCharge, 'Nonrefundable Prepaid Finance Charge'], | |
[notApplicable, 'N/A'], | |
]); | |
| |
function determineFeeName(stateAbbr) { | |
const feeTypes = feeNameMap.entries(); | |
let entry = feeTypes.next(); | |
while (entry.done === false) { | |
const [appliesTo, feeName] = entry.value; | |
if (appliesTo.has(stateAbbr)) return feeName; | |
entry = feeTypes.next(); | |
} | |
} | |
| |
console.log(determineFeeName('CO')); // Flagship Origination Fee | |
console.log(determineFeeName('IN')); // Nonrefundable Prepaid Finance Charge |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment