JavaScript if far from being the best-designed language in the world. I personally often feel myself like in the mine field when coding in it. But it evolves and gets better and better. I can increasingly better express the ideas in JavaScript and I feel it becomes truly powerful and pretty pleasant language to use. Here, I want to share how today one can calculate the sum of the array of numbers. The example is contrived but this example is always used in the schools…Continue Reading “Using array destructuring and recursion to make your JavaScript algorithms shine”

Recently I could not figure out how to types-safely update immutable object in TypeScript. The problem is that in JavaScript the object spread feature is used for this task, like so: let o1 = { x: 5, y: 6 }; o1 = { …o1, y: 10 }; console.log(JSON.stringify(o1)); // “{‘x’:5,’y’:10}” But if you have accidentally missspelled the property you want to update, object spread will add a new propery instead of updating old one: interface Point { x: number, y: number } let o1: Point…Continue Reading “Updating an immutable object in TypeScript”