Sunday, July 3, 2016

HackerRank: AorB - JavaScript code study

July 3, 2016
Problem statement on HackerRank:
https://www.hackerrank.com/contests/june-world-codesprint/challenges/aorb

Work on JavaScript code on HackerRank AorB submission - code study:

1.
https://gist.github.com/jianminchen/b5ce95c07e3dd027e3753b8c81f00c74

2.
https://gist.github.com/jianminchen/2f6b252009868ebcf4d0449aafa01b30

Statistics:
Only 2 submissions score 50/50. So, study those two submissions.

Notes for code 1:
The code is so beautiful!

Great ideas to highlight (Go over it 30 minutes):
1. line 13 - line 30
var dec - a map, '0' maps to 0, ..., 'F' to 15, char to integer;
      variable name is called "dec" - very short!
2. line 32 - line 49
var hexBin - a map, hexadecimal char maps to binary format,
    '0' - '0000', ..., 'F' - 'FFFF'
      variable name is called "hexBin" - very good name.
      hexaDecimalToBinaryFormat is too long, remove "To", capital case 'B', so hexBin.

3. line 51 - 68
var hex - a map, binary number to hexadecimal char
     '0000' - '0', ..., '1111' - 'F'

4. line 70 - line 75
function getBinaryArray



Actionable item: 
1. Learn the code, write a C# version using exactly ideas!
Spend 30 minutes to do the workout!

2. Go over excellent code 30 minutes, save time to write code; Julia tries to figure out best design.
10 hours hard work -> 30 minutes work!  (Learn from best student in CMU? :-)




No comments:

Post a Comment