• Custom User Avatar

    Yeah, but... not in the spirit of the exercise, or that doesn't matter?

  • Custom User Avatar

    some() returns a boolean, forEach() does not return a value. A return can be added as a seccond line.

  • Custom User Avatar

    In the description I would not reveal what the underlying task is (i.e. we are just trying to reach some fixed bitstring and that the fitness function calculates the difference between the individual and the solution).

    This already means that there is a unique maximum for the fitness function and it can easily be solved by optimizing individually for each bit (just for each bit test whether 0 or 1 gives a higher fitness value). So there are no dependencies between the bits and the solution cannot get stuck in a local maximum. That's the reason why you need the roulette selection method, the crossover and mutations to begin with, to get out of local maximums but if there are none then what's the point?

  • Custom User Avatar

    So I solved this kata but I had a huge problem with understanding of scope. I was flabbergast trying to figure out why my fitnesses would degrade with each generation. It turned out the two selected chromosomes to seed a new population were being edited when I ran crossover and mutate. I fixed this by doing newPop[0].split('').join('') but I figure there's a better way to go about this. Any tips for a noob?

  • Custom User Avatar

    Array.prototype.each = [].some;
    How about that.

  • Custom User Avatar

    Thanks for providing this explination bkimmel, I would have been lost without it.

  • Custom User Avatar

    So as it turns out I didn't need any regex ... making the problem harder than it needed to be.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    Can you explain to me why the \s+ is needed in this solution? I tried playing around with it some on regexpal and jsfiddle. While its obvious it needs to be there or it won't work, I don't understand why.

  • Custom User Avatar

    Thanks nklein.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution