Created
November 16, 2022 17:24
-
-
Save mizanmahi/b5daa965e4f9f03873c37c050419c06f 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
const district = 'barisal'; | |
const customerCategory = 'residential'; | |
const averageElectricityConsumptionCost = 1800; // tk | |
const unitInfo = { | |
barisal: { | |
residential: [ | |
{ | |
min: 0, | |
max: 50, | |
perUnitCost: 3.15, | |
maxCost: 157.5, | |
}, | |
{ | |
min: 51, | |
max: 100, | |
perUnitCost: 3.95, | |
maxCost: 395, | |
}, | |
{ | |
min: 101, | |
max: 150, | |
perUnitCost: 5.0, | |
maxCost: 750, | |
}, | |
{ | |
min: 151, | |
max: 200, | |
perUnitCost: 6.8, | |
maxCost: 1360, | |
}, | |
{ | |
min: 201, | |
max: 250, | |
perUnitCost: 8.0, | |
maxCost: 2000, | |
}, | |
{ | |
min: 0, | |
max: 300, | |
perUnitCost: 6.2, | |
}, | |
], | |
commercial: [], | |
industrial: [], | |
}, | |
khulna: {}, | |
dhaka: {}, | |
}; | |
const findUnit = (dist, category, cost) => { | |
const smallerUnits = unitInfo[dist][category].filter( | |
(item, i) => item.maxCost < cost | |
); | |
const unit = unitInfo[dist][category][smallerUnits.length]; | |
return unit; | |
}; | |
console.log( | |
findUnit(district, customerCategory, averageElectricityConsumptionCost) | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment