Challenge 17, issues


Hi, I have been working on getting my code working on todays challenge, I have a code that is currently working and showing me the the first and last ship that is visible on the GRID, however it is say does not produce the correct result. I did notice in the challenge notes it talks about showing the furthest west and east boats, marked in B3 and J10, how ever there is no boat in J10, the furthest boat is in I5. is anyone else having a similar issue?


Got the same problem, same result as you


I got the same problem.


May I ask what your current approach is so far? I just finished the challenge. Maybe I can help!


I was trying to find the first and the last element of the array that I used when I was finding the ships, is the qustion asking us to do something different like rank the ships highest to lowest based on the columns that they are in?


The first element of the array is not necessarily the most west

In our case the array should be returning [ ‘B3’, ‘I5’ ] instead of [ ‘B3’, ‘J10’ ] because there is no ship at J10.

I used this for my function:

function shipReport() {
return allShips().slice(1-3);

but it is not producing the correct result either, even though it is producing the correct array.

Edit: I adjusted the code to give an array of the first and last ship and that ended up working ( [ ‘C2’ , ‘I5’] ). But C2 is not the ship that is furthest west. What’s going on?

Full code:


I was able to get it completed, but not fully satisfied with the code.

I first ran allShips() and stored it into an array.
Then sorted the array by the letters. (lower letters would move to the front, higher letters move to the end)
Then return the first and last element of that array.


But there no ship at [‘J10’] so did you created this letter?


No. With the GRID they provide, the code produces the answer [“B3”, “I5”].

But in my testing, if I manually put a ship in J10, then it would be [“B3”, “J10”];


I just solved by using this. So weird before I ran similar code and it didn’t work…

 function shipReport () {
  const newArr = allShips().sort();
  newArr.splice (1, 1);
  return newArr;


The sort is good, but technically the splice doesn’t work.

It only works when there are 3 ships, but if there are more ships it will break.

const test = [“B3”, “C2”,“I5”];
Answer = Array [“B3”, “I5”]

const test2 = [“B3”, “C2”, “D4”,“I5”];
Answer = Array [“B3”, “D4”, “I5”]

After the sort you need to return the first and last element.


Yeah, the exercise seems to be asking for 2 very different things. Though in our case with the given GRID they align and give the same answer, this doesn’t seem like it would always be the case. I suppose it depends on how you have your allShips array arranged - one would need to flip it so that rows are nested inside columns, and not vice-versa. As already mentioned, the way it is now, “last” does not necessarily mean “most East/right.” Something in J1 would come after something in H10, for example.


I think you need to re-think how you define “most west/most east” Given our grid, can’t you think of the value with the lowest column as ‘westmost’ and the highest column as “eastmost”?

We already have a function allShips() that gives you an array of all the ships. We have a function convertColumn that tells you the value. So if one were to simply parse your array for the lowest and highest columns, you’d have your westmost/eastmost ships, no? Or if there was simply a way to put the array in alphabetical order…

One thing I’m proud about my solution is that if you pass it an array of a single ship (ex. [B3]) it returns [B3, B3] because B3 is both the westmost and eastmost ship.


Yes, sorting each ship by column value could certainly give you West/East-most ships. What I meant was, in order for West/East-most to be considered the same as “first” and “last” with the Grid we’re given (without changing it by sorting), it would have to be different (not that it’s impossible). Would you not consider a ship in coordinate J1 to be “after” a ship in coordinate H10, given that we typically read grids left-to-right, THEN top-to-bottom? The previous exercises assume this way of reading as well, do they not? Otherwise, the “first rock” would be B8, not D1.


I guess I don’t understand what you are trying to say.

Yes J1 is after H10 - A is west (first) and Z would be farthest east (last). In this particular GRID J is farthest east.

The allShips function give you - Array [“C2”, “B3”, “I5”]
“B” is farthest west, “I” is farthest east.
Sorted by letter - [“B3”, “C2”, “I5”]
First is “B3”, last is “I5”


Oohh. Yeah, all I’m saying is that the first and second paragraph for the challenge description ask for two different things. The first paragraph says they want “first and last” and even “similar to firstRock() and firstCurrent()” - which, as your initial allShips array shows, would mean they want C2 and I5. The second paragraph, however, says West/East, which would mean they want B3 and I5.

If “Environment Canada” always considered “first” to be assuming an order by column, then “first rock” would be B8, which I assume was not an acceptable answer.


I see what you are saying. They took this function a step farther, with geographical locations (East and West) of the physical grid.


Right. If I take the first paragraph to just mean “You need to grab the first AND last of some array this time” and the second paragraph to say “and that array should be ordered by column, not by row as it was previously,” then it makes sense. Just misleading description, is all. Thanks for helping me sort that out in my brain!


Consider the lighthouse metaphor again, @jwitow. The beam from the lighthouse on the shore sweeps across the ocean from west to east. Transport Canada wants to know the location of the first and last ships that our lighthouse sees in that area (not the first and last that we read on a grid-based map that represents the area).


Similar to @Scramblelock, I “passed” with a returned array of [ ‘C2’, ‘I5’ ] by mistake when I was testing my code (ran in LHL code editor by mistake when I was restructuring and was surprised to get the congrats message).

The challenge asks for [‘B3’, ‘J10’] but as noted by others the correct answer should be [‘B3’, ‘I5’] , the most west and east ships regardless of north/south position. Argh! Should I just accept the “win”? lol

Im just confused now :frowning: