Image for post
Image for post

Back couple years ago, I started to explore ways to hedge risk when things is going to be risky. After some experimentation that costed me time and money, I started to understand more and thus the problem with it.


Once a risk is discovered, trying to understand or minimize it is definitely a positive move. Therefore the strategy of applying hedge to your portfolio (or your project) is a common move.

You’d like to buy an insurance in case bad things happens in future period of time with some cost.

How difficult is writing a for loop?

Image for post
Image for post

We start programming by learning how to perform a loop, such as the following example.

for (let i = 0; i < 6; i++) { print i; }

I don’t know if this bothers you, but looping isn’t pretty to look at. Not to mention the additional boilerplate as well as keeping track of the extra index. Moreover it breaks the flow of your reasoning. Mentally you have to take a break whenever you encounter a loop.

It is costly, for sure, we don’t want to approach problem in higher dimensions, we tend…

Is this level of trouble worth it in the end?

Image for post
Image for post

Like any tech-savvy person who would chase the latest computer spec, I’m very much into understanding what’s really going on with a new language, especially when the new language starts to show its potential in practical fields.


The learning isn’t that difficult, at least not the beginning. I’ve been practicing the functional programming, comfortable of functions as a first class citizens, and strongly feeling that function probably is what the programming is about, not the implementation.

>>> length (takeWhile (<1000) (scanl1 (+) (map sqrt [1..]))) + 1

With recursive feature…

Image for post
Image for post
Views of Modern Rome, Ravensburger Jigsaw Puzzle, 5000 Piece.

Me and my wife together finished a 5000 pieces of jigsaw. We attempted this project couple of years ago before we had our son, but failed since none of us had a clue how we could finish it back then.

But this year is different, I guess time is all we have. So we gave it another shot, of course this time we were mentally prepared before we started. That is very important.


Solving puzzle isn’t easy especially when it comes to the magnitude of 5000, because taking 500 pieces as a typical task, dealing with 10 of them at…

Image for post
Image for post
My desk with Bee Mine! 2/13/2021

We implemented a “Single Repo System” a while back successfully, where we added features for multiple domains embedding small websites inside a website. In this article I’d like to extend this model to multiple instances. For instance, there could be different features on different instance, even for the same feature, it might be subtle workflow difference for each instance. Most of commercial products these days, when sold to customers with different needs, are having this built in core.

The gain of using single repo is, obviously in the sense, that most of features done in the past could potentially get…

Image for post
Image for post

After ES6, we tend to use map, filter a lot. And sometimes if we really need to get hands dirty, we can use reduce where we take an initial state and reduce it to next state going through all elements.

Looping through the entire array can be a bit expensive, especially when you want to stop when certain condition is met. This conditional reduce can be implemented using a Lazy library, where each element traverse is deferred till needed, therefore only loops to the point when a match is found. …

Image for post
Image for post

ES6 adds quite a bit functionalities to array with map, filter etc. They are extremely handy, but I start to have trouble keeping track of the indexes.

For instance

arr.filter(v => v == 3)

We can find out if there’s a specific element that we need, however once it’s filtered, we lost its original index. Therefore we tend to use indexOf. But the point here is that we do want to filter, at the same time we need to have additional properties to be preserved during the process.

In order to do that, we could do

arr .map((v, i) =>…

Image for post
Image for post
Sophia’s first version of iPad

Create an array in Javascript isn’t 100% straightforward as in other languages. Although on the surface it does seem simple, and most of the online tutorial can put you in the right (working) direction. Does it occur to you it’s not well designed?

Consider the following array statement, what’s odd is that

const a = new Array(10)
  • the elements aren’t initialized, so you can’t apply map right away
  • the element type has to be resolved after the fill

There’re many libraries (even ES6) extending the array functionalities, but they rarely talk about the definition or the initialization of the array…

Question: Advent of Code 2015, Day 3



import Data.List (nub)type Pos = (a, a)next :: (Num a) => Pos -> Char -> Pos
next (x,y) '^' = (x, y+1)
next (x,y) 'v' = (x, y-1)
next (x,y) '<' = (x-1, y)
next (x,y) '>' = (x+1, y)
next (x,y) _ = (x,y)
visited :: Num a => [Char] -> [Pos]
visited = scanl next (0,0)
uniqueVisits :: Eq a => [a] -> Int
uniqueVisits = length . nub
-- Nefrubyr's every from StacksOverflow every :: Int -> [a] -> [a] every n xs…

Question: Advent of Code 2015, Day 2



Given a box as string 2x2x2, we can split it as measurements that can be applied to wrapping paper calculation.

type Box = [Char]split :: Box -> [Int]
split "" = []
split s = fp : rest
where parts = break (=='x') s
fp = read (fst parts)::Int
rest = split $ drop 1 $ snd parts
wrapBox :: [Int] -> Int
wrapBox b@(l:w:h:[]) = area + minimum b
where area = sum d * 2
d = zipWith (*) [l, w, h] [w, h, l]


Fang Jin

Front-end Engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store