hello, I am having trouble figuring out how to iterate through the string and pushing each character into the new subarray without pushing the entire string.
Right now it is only pushing the very first character into each subarray
Your code so far
function pairElement(str) {
let newArr = new Array();
let finalArr = new Array();
for (let i = 0; i < str.length; i++){
newArr.unshift(str[i]);
newArr.length = 1;
finalArr.push(newArr);
}
console.log(finalArr);
}
console.log(pairElement("ATCGA"));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Challenge Information:
Implement a DNA Pair Generator - Implement a DNA Pair Generator
if you see it you may understand better when I tell you that you are pushing the same array to finalArr multiple times, so being always the same array they will all be the same
actually I think I got it to push them into new sub arrays correctly:
function pairElement(str) {
let newArr = [];
for (let i = 0; i < str.length; i++){
newArr.push([str[i]])
}
return newArr;
}
console.log(pairElement("ATCGA"));