Sort:  

Haven't optimise yet and a few error need a better explanation, but it works.

Didn't know the project is written in TypeScript, should have used that.