2019-05-25 13:37:38 +03:00
|
|
|
export const getReputation = reputation => {
|
2018-09-30 03:37:26 +03:00
|
|
|
if (reputation === null) return reputation;
|
|
|
|
|
2019-06-04 10:23:46 +03:00
|
|
|
let _reputation = String(parseInt(reputation, 10));
|
2018-09-30 03:37:26 +03:00
|
|
|
|
2018-10-04 05:18:36 +03:00
|
|
|
const neg = _reputation.charAt(0) === '-';
|
2018-09-30 03:37:26 +03:00
|
|
|
_reputation = neg ? _reputation.substring(1) : _reputation;
|
|
|
|
|
|
|
|
const str = _reputation;
|
2019-06-04 10:23:46 +03:00
|
|
|
const leadingDigits = parseInt(str.substring(0, 4), 10);
|
2018-09-30 03:37:26 +03:00
|
|
|
const log = Math.log(leadingDigits) / Math.log(10);
|
|
|
|
const n = str.length - 1;
|
2019-06-04 10:23:46 +03:00
|
|
|
let out = n + (log - parseInt(log, 10));
|
2018-09-30 03:37:26 +03:00
|
|
|
|
2019-06-04 10:23:46 +03:00
|
|
|
// eslint-disable-next-line no-restricted-globals
|
2018-09-30 03:37:26 +03:00
|
|
|
if (isNaN(out)) out = 0;
|
|
|
|
|
|
|
|
out = Math.max(out - 9, 0);
|
2019-06-04 10:23:46 +03:00
|
|
|
out *= neg ? -1 : 1;
|
2018-09-30 03:37:26 +03:00
|
|
|
out = out * 9 + 25;
|
2019-06-04 10:23:46 +03:00
|
|
|
out = parseInt(out, 10);
|
2018-09-30 03:37:26 +03:00
|
|
|
|
|
|
|
return out;
|
2018-08-01 22:24:34 +03:00
|
|
|
};
|