Mysterious Organism Challenge Project (JavaScript)

Hi everyone !

You can check my solution here.
Hope it works for you !

Happy coding !

Good Evening Everyone (11:00pm South African Time)

This is my solution to the project.

A Couple of notes:

  1. I plan to refactor it quite a bit to convert certain code such as for loops into iterators.
  2. Having completed the additional items, that is on the To Do.
  3. I think there might be a bug as i’m not 100% certain as to what the final result should be.
  4. I do plan on adding more functionality to it, such as relaying information to the console to make it more readable in terms of the samples themselves.

In the final step, the project calls for 30 samples of DNA which will survive (containing 60% of either C or G Bases). Does this include after the samples mutate?

I’m finding that surviving DNA is being stored in the Samples array, however, when it is mutated, then some will fail (Die)

Again any other suggestions and information is welcome.

My solution for Mysterious Organism:


How long? It depends on your concentration levels, I’ve spent 3 - 4 hours today on this project and completed it start to finish. I have had distractions around me: TV, family ect. If you can find a quiet space to work, it may help.

This being said, take your time, carry out research when you don’t understand. By googling keywords and array methods, you will develop a deeper understanding of the task and ways of approaching it.

If you’re not enjoying yourself, don’t force it. Try a fresh challenge, revisit the learning material, or take a break. Manipulating arrays isn’t everyone’s cup of tea. :slight_smile:.

extremely helpful feedback. Thanks

1 Like

Hi, please see my solution here. Any feedback appreciated.

Here is my version. Please look it over.

Hello all!

Did anyone else complete the challenge option - using .compareDNA() to find the two most related organisms - and get some interesting results?

The most efficient way to do this that I could think of was to simply use nested for loops to check each index of the array of organisms. The outer loop iterates over every index, while the inner loop iterates starting at the outer loop’s index plus one. This avoids comparing the same index to itself, or to lower indices, which it’s already been compared to.

Interestingly, though, with the population of 30 the comparison only ever returned a similarity of about 60%. Specifically it only returned 60, 66.67, or 73.33%. Tried again with a population half the size - a similar effect - only saw it return 60 or 53.33%.

Now I’m no mathematician, but that doesn’t look particularly random. I know there’s a bit of a lower bound on this number - the specimens are all fairly similar to each other because they all have at least 60% C and G bases. But I’d expect to see more variety. Maybe a higher percent of similarity is just so unlikely, in a 15-base-long sequence, that I didn’t run the program enough times to see it? Would love to see the results you guys got.

Hey, I found somethign quite similar, although I don’t know enough stats to explain it. I ran it a load of times to see.

I created a function to generate 30 pAequor and find then record the closest and furthest matches, then rinse and repeat 1000 times:

function multiArray (loops) {
  let highScore = 0; 
  let lowScore = 100;
  for (let i = 0; i < loops; i++) {
    let pAequorArray = generatepAequorArray(30); //creates a sample of 30
    let currentArray = findMostRelated(pAequorArray); //  find the closest match
    highScore = Math.max(highScore,currentArray[2])
    lowScore = Math.min(lowScore,currentArray[2])
  return results = {
    'high score' : highScore,
    'low score' : lowScore
console.log(multiArray(1000)) link:

That delivered a highest match of 87% and a low of 53%, which is quite a bit more variance. Maybe once I learn a bit I would be able to get my code to plot the high and low points of each loop and get an overall picture of the distribution.
I ran the code a second time and the highest match was 80% (lowest was 53 again).

Quite interesting.

(on a separate note I love j = i + 1 in your loop.)

EDIT: Also intersting that it doesn’t drop below 53%, as I can easily make two strands that will survive, but are still a 0% match:

const pAequor1 = pAequorFactory(1,mockUpStrand())
const arr1 = pAequor1.complementStrand()
const pAequor2 = pAequorFactory(2,arr1)


Ah, thanks for having the patience to set up a large simulation where I didn’t :joy:

Several runs of the code actually produced a highest match of 93% for me. It looks like a high number of repetitions, in order to catch the rare highly-related organisms, is indeed the secret sauce.

Creative use of Math.max() and .min() on lines 124-5! I’ll have to remember that.

1 Like