Today, there were a bunch of easy ones in a row in the exercism Javascript queue. Lets go over them.

  • Strain – Implement keep/discard that returns a copy of a given array of elements to do/do not match a given function. Even without using filter, this was still way easy, not medium. They seem to just be insulting my solution every time now. Less than thirty lines with comments, so it isn’t length.
  • Flatten Array – Given an array with nested arrays and possibly null values, filter out the nulls and flatten everything into one array. Just remember a recursive call to flatten when you find an array to handle arbitrary nesting and you are good. Basically one line of code and they want me to come back and improve it… groan. I think they just say that every time now (still insulting every time saying my solution needs improvement).
  • Nth Prime – Find the nth prime number for integers > 0. First is 2, fifth is 11, etc. Only hard part is looking up the Sieve of Eratosthenes to figure out how to get an arbitrary number of prime numbers.
  • Sieve – Remember how I referenced the Sieve of Eratosthenes just a moment ago. Well this exercise is to implement that. Really should have had this one before that one.
  • Rotational Cipher – Pretty much a Caeser Cipher – given a number for each letter in the message move the letter forward by the number of spaces wrapping back around to A if you pass Z
  • Diffie Hellman – Hey look I needed to validate a prime number again and used some code from Sieve (slightly modified) above. Anyway you are exchanging some public and private keys to generate a secret key. Lots of sanity checks. The tricky part is they want to call a method from the class instead of the instance so I had to put the static keyword in front of it. In the community solutions, I saw I should only iterate up to sqrt(maxValue) when checking for primes so I fixed that and resubmitted a second iteration. Even with an iteration they still talk down to my solution.

With that, I am finally at 1 to 1. Javascript exercises to 100 Days of Code. If I do one a day average I should be done on the last day of 100 Days of Code.

On to Super GameBoy demos. I figured out what I did wrong with yesterday’s Super GameBoy sample program. In translating the changed hardware constants I used B_JOYP_SGB_ZERO, and B_JOYP_SGB_ONE instead of JOYP_SGB_ZERO, and JOYP_SGB_ONE for P1F5, and P1F4. (There is a B_ in front).

After that I got yesterday’s sgb_color_base and today’s sgb_color_transfer_pal program working as expected. I also compiled sgb_color_transfer_index, sbg_color_index, and sgb_color_transfer_combined. I think I missed the reference to compile them when reading previously. The ZeroMemory macro changed which also caused a problem along the way.