Skip to content

Instantly share code, notes, and snippets.

@pszafer
Created May 25, 2021 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pszafer/614a5501b386e7b6b4ae97f26642f95f to your computer and use it in GitHub Desktop.
Save pszafer/614a5501b386e7b6b4ae97f26642f95f to your computer and use it in GitHub Desktop.
const input = JSON.parse(msg.data.replace("eval(", "").replace(",],", "],").slice(0, -1));
const today = new Date()
const data_d = today.getDay();
const data_m = today.getMonth()+1;
const smieci = ["makulatura", "szklo", "zielone","kuchenne","resztkowe", "mix", "gabaryty" ]
const inputSortedByKind = input["dane"].reduce((acc, curr) => {
acc[curr["rodzaj"]].push(new Date(2021, +curr["data_m"]-1, +curr["data_d"]))
return acc
}, {
"makulatura": [], "szklo": [], "zielone": [],"kuchenne": [],"resztkowe": [], "mix": [], "gabaryty": []
})
for (var smiec of smieci){
let found = inputSortedByKind[smiec].find(e => e >= today)
if (found){
msg[smiec] = found
}
}
msg.data = null;
return msg;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment