Use destructuring and template string for formatDuration (#720)

This commit is contained in:
Sergei Zhernosek
2018-08-27 16:52:06 +03:00
committed by Felix Wu
parent 566d4b3a0b
commit 44eea3e9ed
2 changed files with 2 additions and 2 deletions

View File

@ -19,7 +19,7 @@ const formatDuration = ms => {
}; };
return Object.entries(time) return Object.entries(time)
.filter(val => val[1] !== 0) .filter(val => val[1] !== 0)
.map(val => val[1] + ' ' + (val[1] !== 1 ? val[0] + 's' : val[0])) .map(([key, val]) => `${val} ${key}${val !== 1 ? 's' : ''}`)
.join(', '); .join(', ');
}; };
``` ```

View File

@ -9,7 +9,7 @@ const formatDuration = ms => {
}; };
return Object.entries(time) return Object.entries(time)
.filter(val => val[1] !== 0) .filter(val => val[1] !== 0)
.map(val => val[1] + ' ' + (val[1] !== 1 ? val[0] + 's' : val[0])) .map(([key, val]) => `${val} ${key}${val !== 1 ? 's' : ''}`)
.join(', '); .join(', ');
}; };
module.exports = formatDuration; module.exports = formatDuration;