Created
November 3, 2019 09:37
-
-
Save Kamilnaja/ade6732ee014adae075078f0e3fd8aab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
let rawData = fs.readFileSync('data.json'); | |
let data = JSON.parse(rawData); | |
const convertToNumber = item => { | |
item.workTimeRangeSum = Number(item.workTimeRangeSum.split(':').join('.').replace(/\.3/g, '.5')); | |
return item; | |
} | |
const res = data.workDays | |
.map(item => { | |
item.dayOfWeek = new Date(item.day).getDay(); | |
return item; | |
}) | |
.map(item => { | |
if (item.dayOfWeek === 0) { // sunday | |
item.rate = 150; | |
} else if (item.dayOfWeek === 6) { // saturday | |
item.rate = 120; | |
} else { | |
item.rate = 100; | |
} | |
return item; | |
}) | |
.map(convertToNumber) | |
.map(item => { | |
return { | |
workHours: item.workTimeRangeSum, | |
rate: item.rate | |
} | |
}) | |
.filter(item => item.workHours) | |
.reduce((acc, item) => { | |
acc[`hours${item.rate}`] = acc[`hours${item.rate}`] + item.workHours; | |
return acc; | |
}, { | |
'hours100': 0, | |
'hours120': 0, | |
'hours150': 0 | |
}) | |
console.log(res); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment