Posts

Showing posts from August 14, 2018

Transforming data from an API using Typescript and Lodash

Image
Clash Royale CLAN TAG #URR8PPP .everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0; up vote 3 down vote favorite As a front-end developer, I am given the following result from an API, an array of objects that looks like: [ Color: "#065b79", GroupName: "VXYZ", QuoteCount: 4, SortOrder: 0, TabCategoryID: "CHSI1", TabCategoryName: "Workers' Compensation", TabCategoryOrder: 0, TabID: 1, TabName: "new" ] I need to display the data in a more hierarchical/nested format: [ GroupName: 'VXYZ', TabCategories: [ TabCategoryID: 'CHSI1', TabCategoryName: "Workers' Compensation", TabCategoryOrder: 0, Tabs: [ Color: '#065b79', SortOrder: 0, TabID: 1, TabName: 'new', QuoteCount: 4 ] ] ] Any data in an array can have any number of array items. In the models above, I just use a single instance of each array item. This is the cod...

Inserting into a binary expression tree with GOTO

Image
Clash Royale CLAN TAG #URR8PPP .everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0; up vote 5 down vote favorite I'm working on a binary space partition tree. For the time being, the nodes are only inserted into the right. A node that has children will have 0 as data. Here are the insertion rules. If the insertion node has data and no parent, the current data becames the left child, and the node to insert goes to the right. 1 0 ^ ---> / 1 2 If the node has a parent, is a the left child of the parent and has data, the node is reinserted in the parent's right node, and the inserted node takes its place 0 0 / / 1 2 ---> 3 0 ^ / 2 1 I'd like to have a feedback on my insert function. I put a goto statement to not repeat code, but I'd like to avoid it to make the function more clear. Live on Coliru with verbose output #include <assert.h> #include <stdlib.h> #include <stdio.h> struct node int da...