Skip to content

Instantly share code, notes, and snippets.

View varunrayen's full-sized avatar
👋
Stay home, Stay safe!

Varun Rayen  varunrayen

👋
Stay home, Stay safe!
View GitHub Profile
@varunrayen
varunrayen / sortCategoriesForInsert.js
Last active June 25, 2021 11:26
Sorting a category list from a flat database for insert into a hierarchy-constrained one
module.exports = function sortCategoriesForInsert (inputJson) {
let dataTree = function (inputJson, root) {
var r = [], o = {};
inputJson.forEach(function (a) {
o[a.id] = { data: a, children: o[a.id] && o[a.id].children };
if (a.parent_id === root) {
r.push(o[a.id]);
} else {
o[a.parent_id] = o[a.parent_id] || {};
{
"meta": {
"theme": "stackoverflow"
},
"basics": {
"name": "Varun Rayen",
"label": "Full Stack/DevOps Engineer",
"picture": "",
"email": "hello@varunrayen.me",
"phone": "(+91)-9994043105",