Tag Archives: javascript

React: How To – a guide by example

github.com/brunolm/react-how-to is a repository that shows how to do things by example.

Each Pull Request on this repository is a complete guide on how to do something, for example if you want to add redux to your project you can just check this Pull Request and see some instructions and all changes required.

If you want to setup tests check this Pull Request.

Better than just reading some instructions you get a full example and a working project as a guide.

guide

Enjoy!

Advertisements

How I solved Bomberman challenge on HackerRank

I found a challenge called “The Bomberman Game” on HackerRank and I found it pretty interesting.

It boils down to something like this:

The Bomberman Game

Rules

  • Bombs will explode in 3 seconds
  • When a bomb explodes it clears its tile and 1 tile up, down, left, right
  • Bombs that are about to go off explode at the same time
  • There are no chain reactions
  • If a bomb explodes next to another that is not about to go off then the nearby bomb is just cleared

Iteration

  1. Bomberman plants some bombs (you’re given an input with the map)
  2. A second passes
  3. A second passes. Bomberman plants bombs on all empty slots
  4. A second passes
  5. Repeat 3 and 4 until N seconds passes

Input

  • R = number of rows
  • C = number of cols
  • S = number of seconds
  • O = bomb
  • . = empty
R C S
O..
...

Task

Return the map after N seconds have passed.


Solving

The first thing I though was to solve it with a generator (well, there was no real need to use it, but since it is about a game I thought it would be fun to be able to access any state of the game).

Continue reading

TypeScript vs JavaScript

TypeScript is JavaScript with types, to put it simple.

  • How do I install?
    • npm i -D typescript
  • Does it work on Linux/Mac?
    • Yes
  • Does my editor support it?
  • Do I have to learn a whole new language? Like CoffeeScript, Dart…?
    • No! Absolutely no!┬áIf you know JavaScript you know 95%. The remaining 5% or less is basically configuration.
  • Any big companies using it?
  • Does it support React?
    • Yes. `.tsx` files.
  • Have you ever coded a real project with it?
    • Yes and I actually kept it compatible with the architecture of other (js) projects in my company. One of the projects is scaling.
  • How many bugs did you prevent?
    • Over 9000… A lot and very recently I found a bug in production in a very big project that would never happen if it was coded in TypeScript.
  • Do you still use babel?
    • Not if I get to choose which version of node I will be using. For some old versions some polyfills are really good… TypeScript does not add polyfills, it does not change your code more than enough to support a few ES features. You can check it out for yourself on TypeScript playground, the playground targets ES3, so if you use arrow functions or async/await TypeScript will “alter” your code.

Continue reading