Skip to content

Instantly share code, notes, and snippets.

@burdenless
Last active October 14, 2021 18:13
Show Gist options
  • Save burdenless/8e420a981e3812ae6f3ad3ca3181833a to your computer and use it in GitHub Desktop.
Save burdenless/8e420a981e3812ae6f3ad3ca3181833a to your computer and use it in GitHub Desktop.
File for Chris' project
// Returns a random DNA base
const returnRandBase = () => {
const dnaBases = ['A', 'T', 'C', 'G'] // Adenine, Thymine, Cytosine, and Guanine. 4 Bases of DNA
return dnaBases[Math.floor(Math.random() * 4)]
}
// Returns a random single stand of DNA containing 15 bases
const mockUpStrand = () => {
const newStrand = []
for (let i = 0; i < 15; i++) {
newStrand.push(returnRandBase())
}
return newStrand
}
const pAequorFactory = (specimenNum, dna) => {
return {
specimenNum : specimenNum,
dna : dna
}
}
const mutate = (dna) => {
let randomIndex = Math.floor(Math.random() * dna.length);
let newBase = returnRandBase();
while (newBase === dna[randomIndex]) {
newBase = returnRandBase();
}
dna[randomIndex] = newBase;
return dna;
}
const compareDNA = (pAequorObject) => {
let total = 0
for (let i = 0; i < this.dna.length; i++) {
if (pAequorObject.dna[i] === 'C' || this.dna[i] === 'G') {
total++;
}
}
}
@burdenless
Copy link
Author

To run this script, open a terminal and run:

node

This will open a Node environment, and then run:

.load main.js

Now the functions from your file main.js will be available to run, like this:

mutate(['f'])
[ 'G' ]

pAequorFactory(10, mockUpStrand())
{ specimenNum: 10,
  dna: [ 'G', 'C', 'C', 'C', 'T', 'C', 'C', 'G', 'A', 'G', 'T', 'T', 'C', 'C', 'A' ] }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment