var calc = (function() {
const data = [{
postfix: 'k',
number: 1000
},
{
postfix: 'kk',
number: 1e6
}
].sort(function(a, b) {
return a.number - b.number;
});
return function(value) {
const item = data.reduce(function(r, i) {
if (value >= i.number)
r = i;
return r;
}, false);
return !item ? value : (value / item.number).toFixed(1) + item.postfix;
};
})();
alert(calc(145));
alert(calc(145800));
alert(calc(6458300));