Challenge 15 Help - What a I doing wrong


#1

function allTargets(target) {
let currentsArr = [];
GRID.forEach((row, index) =>{
row.forEach((cell,indexTwo) => {
if (cell == “^”) {
currentsArr.push(${String.fromCharCode(65+indexTwo)}${index+1});
}
});
});
return currentsArr;
}

function firstRock(){
let rocks = allTargets("^");
first_rock = [];
first_rock = first_rock.push(rocks);
return first_rock[0];
}


#2

Anyone know what I am doing wrong my allTarget() worked for day 13 and 14


#3

I am assuming that you used allTargets() for your allRocks() implementation.

Now I think the problem is your implementation for firstRock(). When you push rocks to first_rock, it would become something like this:

function firstRock(){
    let rocks = allTargets("^"); // output is ['D1', 'E3', 'F3', 'E4', 'F4', 'B8', 'H8', 'B9', 'B10']
    first_rock = [];
    first_rock = first_rock.push(rocks); // output is [['D1', 'E3', 'F3', 'E4', 'F4', 'B8', 'H8', 'B9', 'B10']]
    return first_rock[0]; // returns ['D1', 'E3', 'F3', 'E4', 'F4', 'B8', 'H8', 'B9', 'B10']
}

This is because you are pushing the whole array of rocks, making your first_rock an array of array(s).

Now here’s my hint for you, take a look at your implementation of allRocks(). It should return the same thing as your rocks. Then, you just need to return the first element of that.

Hope this helps!


#4

@exoceus why don’t you just use allRocks() function and call the first element of the array?


#5

how do i do that? I tried doing this

function firstRock(){
return allRocks()[0];
}


#6

Yeah, this is what I ended up doing. Is it not working? It might be because of your previous implementations in other functions.