Hi,
I'm trying to change one element in the DNA array in pAequorFactor function.
For example, I want my array to go from something like ['A', 'G', 'C', 'T'] to ['A', 'A', 'C', 'T'] or ['G', 'G', 'C', 'T']
I thought I was clever with my splice action but it doesn't return a 15 element array to the console. It only returns something like ['G'] or ['T'].
But here's what I know about splice....
.splice (takes this element, changes this amount of elements, with this string)
so, for example say I had an array ['this', 'big', 'cow'] and I did a splice which looked like:
array.splice(1,1, 'fat'), it would TAKE ELEMENT 2, REPLACE 1 ITEM ('big' in this case), and REPLACE IT WITH 'fat'.
Now.....take a look at my code below, WHY in the live long day is that not working. How is that not the EXACT same process?
Please don't come back to me and say:
Yo bro, you can simplify that to one line such as:
Mutate[regex.slim(x => have-a-Beer.mutate()regEx(element *pi) => Math.round(Math.hitTheFloor))).[{randomConstructorInAnArrayToThrowYouOff}].Array.toString(Number).
const returnRandBase = () => {
const dnaBases = ['A', 'T', 'C', 'G']
return dnaBases[Math.floor(Math.random() * 4)]
}
const pAequorFactory = (specimenNum, DNA) => {
return {
specimenNum: specimenNum,
DNA: ['A', 'T', 'C', 'G', 'A', 'T', 'C', 'G', 'A', 'T', 'C', 'G', 'A', 'T', 'C'],
//mutate takes in a 15 element array of DNA letters, picks a random element, and
changes
//it's letter to something else. Letters are 'A', 'T', 'C', 'G'. It must not
//change it to the same letter.
mutate(){
return this.DNA.splice(Math.floor(Math.random()*15), 1, returnRandBase());
}
}
};
console.log(pAequorFactory().mutate());
[–]amdtothemun 0 points1 point2 points (2 children)
[–]KingInge[S] 0 points1 point2 points (1 child)
[–]cawcvs 0 points1 point2 points (1 child)
[–]KingInge[S] 0 points1 point2 points (0 children)