debugger;

  1. Write debugger; as the first line inside your function.
  2. Inspect Element.
  3. Run the function in the Console and look at the Sources tab.  (The ‘debugger;‘ line should be highlighted in Sources).
  4. ‘Step over the next function call’ to test the code line by line as it’s running.
  5. ‘Step into the function’ if you want to go inside the callback function that’s inside the function you’re debugging.

* Create a separate function to run the debugger on any function instead of having to write debugger; in each of our function.

function runWithDebugger (ourFunction) {
    debugger;
    ourFunction();
}
debugger;

Exercism Ruby: Hamming

Write a program that can calculate the Hamming difference between two DNA strands.

A mutation is simply a mistake that occurs during the creation or copying of a nucleic acid, in particular DNA. Because nucleic acids are vital to cellular functions, mutations tend to cause a ripple effect throughout the cell. Although mutations are technically mistakes, a very rare mutation may equip the cell with a beneficial attribute. In fact, the macro effects of evolution are attributable by the accumulated result of beneficial microscopic mutations over many generations.

The simplest and most common type of nucleic acid mutation is a point mutation, which replaces one base with another at a single nucleotide.

By counting the number of differences between two homologous DNA strands taken from different genomes with a common ancestor, we get a measure of the minimum number of point mutations that could have occurred on the evolutionary path between the two strands.

This is called the ‘Hamming distance’.

It is found by comparing two DNA strands and counting how many of the nucleotides are different from their equivalent in the other string.

GAGCCTACTAACGGGAT
CATCGTAATGACGGCCT
^ ^ ^  ^ ^    ^^

The Hamming distance for the above DNA strands is 7.

This is the test suite that my code has to pass:

My solution:

screen-shot-2016-12-05-at-9-36-36-pm

Took me a while to get used to exercism’s format of defining a class first (don’t give it the same name as the test) and then defining the method with self.compute

The BookKeeping module at the end of the code to keep track of the version of the given test, which is version 3 in this case.

Here are more implementations of this problem.

Exercism Ruby: Hamming