fix: remove common/utils.

This commit is contained in:
elforjani13
2021-09-21 19:19:28 +02:00
parent f15184091a
commit 413293cc59
2 changed files with 2 additions and 35 deletions

3
.gitignore vendored
View File

@@ -1,2 +1,3 @@
/data
.env
.env
/node_modules

View File

@@ -1,34 +0,0 @@
function roundTo(num, to = 2) {
return +(Math.round(num + "e+" + to) + "e-" + to);
}
const flatToNestedArray = (
data,
config = { id: 'id', parentId: 'parent_id' }
) => {
const map = {};
const nestedArray = [];
data.forEach((item) => {
map[item[config.id]] = { ...item };
map[item[config.id]].children = [];
});
data.forEach((item) => {
const parentItemId = item[config.parentId];
if (!item[config.parentId]) {
nestedArray.push(item);
}
if (parentItemId) {
map[parentItemId].children.push(item);
}
});
return nestedArray;
};
export default {
roundTo,
flatToNestedArray,
};