My learning diary


I thought consolidating constants was evil. Just two or three dozens of them were enough to become a huge headache for me. In Java, this practice is frowned upon. In JavaScript, it seemed alright. The answer which received the bounty recommended the following: // Warning: This answer was written in 2014. module.exports = Object.freeze({ MY_CONSTANT: 'some value', ANOTHER_CONSTANT: 'another value' }); It was my first time encountering Object.freeze, so I went to google for the difference between Object.

Continue reading "Constants"

Javascript heap limit

For the past week, I could not fathom why my diffs seemed to not be on hot reload. It turned out to be a JavaScript heap limit problem. As a result, the codebase did not rebuild and remained stale. This issue does not happen to everyone. I am using a MacBook Air (13-inch, 2017) with 8 GB of RAM. Notice the line above the last which says, FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory.

Continue reading "Javascript heap limit"

String.format equivalent in TypeScript

While working on a problem during work, I thought I needed a way to do a String.format equivalent operation in TypeScript (it turns out I didn’t need to). I didn’t want to install Lodash (50 kB for _.template alone) or sprintf (40 kB), so I came up with the following: // Warning: Untested code export const compileTemplate = (template: string, values: Map<string, string>) => { const variables = Array.from(values.keys()).map(key => ':' + key).

Continue reading "String.format equivalent in TypeScript"

Calculator V2

I made some changes to my compound interest calculator after reading up on “future value”. My calculator will allow users to specify regular deposits. This is so that they can see for themselves the importance of every dollar added to their savings. import nerdamer from 'nerdamer/nerdamer.core'; import Algebra from 'nerdamer/Algebra'; import Calculus from 'nerdamer/Calculus'; import Solve from 'nerdamer/Solve'; const totalMonthsPerYear = 12; export const calcCompoundInterest = ({ principal, depositAmountPerMonth = 0, interestRatePerAnnum, compoundRatePerMonth = 1, totalMonths, }) => { const totalAmount = solveForOneUnknownVariable( 'a=(p*(1+(r/n))^(n*t))+(q*(((1+(r/n))^(n*t)-1)/(r/n)))', { p: principal.

Continue reading "Calculator V2"