Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Yeah, but... not in the spirit of the exercise, or that doesn't matter?
some()
returns a boolean,forEach()
does not return a value. Areturn
can be added as a seccond line.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?
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?
Array.prototype.each = [].some;
How about that.
Thanks for providing this explination bkimmel, I would have been lost without it.
So as it turns out I didn't need any regex ... making the problem harder than it needed to be.
This comment is hidden because it contains spoiler information about the solution
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.
Thanks nklein.
This comment is hidden because it contains spoiler information about the solution