at the end of the day, it was inevitable

This commit is contained in:
Mo Elzubeir
2022-12-09 08:36:26 -06:00
commit 1218570914
1768 changed files with 887087 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
export const normalize = function (arr, entityCallback) {
let ids = []
let entities = {}
arr.forEach((item, i) => {
if (item.id) {
ids.push(item.id)
if (entityCallback) {
entities[item.id] = entityCallback(item, item.id)
}
else {
entities[item.id] = item
}
} else {
ids.push(i.toString())
if (entityCallback) {
entities[i] = entityCallback(item, i)
}
else {
entities[i] = item
}
}
})
return {ids, entities}
}