Skip to content

Commit

Permalink
Fixed wrong symbols count rounding.
Browse files Browse the repository at this point in the history
Issue #5
  • Loading branch information
ivan-nginx committed Jan 22, 2018
1 parent f92312e commit eca327d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
15 changes: 9 additions & 6 deletions lib/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ var getFormatTime = function(minutes) {

module.exports.symbolsCount = function(content) {
var symbolsResult = getSymbols(content);
return symbolsResult < 1024
? symbolsResult // < 999 => 100
: Math.round(((symbolsResult / 1000) * 10) / 10) + 'k'; // > 999 => 1.1k
if (symbolsResult > 9999) {
symbolsResult = Math.round(symbolsResult / 1000) + 'k'; // > 9999 => 11k
} else if (symbolsResult > 999) {
symbolsResult = Math.round(symbolsResult / 100) / 10 + 'k'; // > 999 => 1.1k
} // < 999 => 111
return symbolsResult;
};

module.exports.symbolsTime = function(content, awl, wpm) {
Expand All @@ -41,9 +44,9 @@ var getSymbolsTotal = function(site) {

module.exports.symbolsCountTotal = function(site) {
var symbolsResultTotal = getSymbolsTotal(site);
return symbolsResultTotal < 1024024
? Math.round(symbolsResultTotal / 1000) + 'k' // < 999k => 100k
: Math.round(((symbolsResultTotal / 1000000 * 10)) / 10) + 'm'; // > 999k => 1.1m
return symbolsResultTotal < 1000000
? Math.round(symbolsResultTotal / 1000) + 'k' // < 999k => 111k
: Math.round(symbolsResultTotal / 100000) / 10 + 'm'; // > 999k => 1.1m
};

module.exports.symbolsTimeTotal = function(site, awl, wpm) {
Expand Down
21 changes: 18 additions & 3 deletions test/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit eca327d

Please sign in to comment.