Skip to content

Commit

Permalink
164798029-(article): update reading time function
Browse files Browse the repository at this point in the history
  • Loading branch information
sojida committed Apr 9, 2019
1 parent 6c29804 commit 62a836a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 3 additions & 4 deletions server/helpers/reading-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ const calculateTime = (...args) => {
totalWords = words.split(' ').length + totalWords;
});

const wordsPerMinutes = (totalWords / 200).toFixed(2);
const time = `${wordsPerMinutes}`.split('.');
const minute = parseFloat(time[0]);
const seconds = (parseFloat(time[1]) * 0.6).toFixed(0);
const wordsPerMinutes = Number((totalWords / 200).toFixed(2));
const minute = wordsPerMinutes.toFixed(0);
const seconds = ((wordsPerMinutes % 200) * 0.6).toFixed(0);
if (seconds > 30) {
return Number(`${minute + 1}`);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/reading-time.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ const article2 = {
'Lorem ipsum dolor sit amet consectetur adipiscinge. Ut pulvinar maximus nulla in fermentum. Vivamus eu arcu suscipit, tempor nisi sed, auctor arcu. Nulla gravida lacinia risus a vehicula. Nulla est arcu, auctor sit amet condimentum nomentum mi, sed lobortis dolor. Nam imperdiet orci posuere arcu semper lobortis. Nulla pellentesque sem sed pharetra blandit. Maecenas suscipit lacinia ornare. Lorem ipsum dolor sit amet consectetur adipiscing elit. Proin quis metus sed turpis pulvinar tristique. Ut pulvinar maximus nulla in fermentum.',
};

describe('Slugmaker test', () => {
it('should return slug', done => {
describe('Cacluate time test', () => {
it('should return calculated', done => {
expect(readingTime(article1.abstract, article1.title)).to.equal(1);
done();
});

it('should return with false', done => {
it('should return calculated', done => {
expect(readingTime(article2.abstract, article2.title)).to.equal(1);
done();
});
Expand Down

0 comments on commit 62a836a

Please sign in to comment.