Skip to content

Instantly share code, notes, and snippets.

@ilyachenko
Last active August 29, 2015 14:00
Show Gist options
  • Save ilyachenko/b64669ad666c6fdba4d2 to your computer and use it in GitHub Desktop.
Save ilyachenko/b64669ad666c6fdba4d2 to your computer and use it in GitHub Desktop.
CumulativeList
var cumulativeList = [
{min: 0.01, max: 9.99, title: '0.01-9.99'},
{min: 10, max: 19.99, title: '10-19.99'},
{min: 20, max: 29.99, title: '20-39.99'},
{min: 40, max: 99.99, title: '40-99.99'},
{min: 100, max: 199.99, title: '100-199.99'},
{min: 200, max: Infinity, title: '200+'}
];
/**
* returns cumulative attribute by amount
* @param {number} amount
* @returns {string}
*/
var getCumulativeAttributeByAmount = function (amount) {
var result = null;
for (var i = 0; i < cumulativeList.length; i += 1) {
if (cumulativeList[i].min <= amount && cumulativeList[i].max >= amount) {
result = cumulativeList[i].title;
break;
}
}
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment