Challenge 10 Megathread

Welcome to challenge 10! Use this thread for any and all questions relating to challenge 10.

Need some help? Watch this helpful tutorial video from Lighthouse Labs full-time instructor Nima (@NimaBoscarino) and Lighthouse Labs Web Development Bootcamp student Charlotte.

6 Likes

Is the test broken again? Here’s a code sample with some test cases

// NOTE ignore my convoluted code up here, see below
const compose = f => g => x => g(f(x))
const contains = result => result !== -1
const findIndex = fn => arr => arr.findIndex(fn)
const isLegalSpot = aSet => ele => aSet.has(ele)
const findCol = compose(isLegalSpot)(findIndex)

const whereCanIPark = (spots, vehicle) => {
  const pred = new Set()
  if (vehicle === 'regular') pred.add('R')
  if (vehicle === 'small') pred.add('R').add('S')
  if (vehicle === 'motorcycle') pred.add('R').add('S').add('M')
  const colFinder = findCol(pred)
  const legalRow = compose(colFinder)(contains)
  const row = findIndex(legalRow)(spots)
  if (row === -1) return false
  const col = colFinder(spots[row])
  if (col === -1) return false
  return [col, row]
}

// NOTE: copy below snippet to test your code

const cases = [
  [ [[], []], 'small', false ]
, [ [[]], 'small', false ]
, [ [['x']], 'small', false ]
, [ [['x'], ['x']], 'small', false ]
, [ [['R']], 'regular', [0,0] ]
, [ [['R']], 'small', [0,0] ]
, [ [['R']], 'motorcycle', [0,0] ]
, [ [['S']], 'small', [0,0] ]
, [ [['S']], 'motorcycle', [0,0] ]
, [ [['M']], 'motorcycle', [0,0] ]
, [ [['x', 'R'], ['x', 'x']], 'regular', [1,0] ]
, [ [['x', 'x'], ['R', 'x']], 'regular', [0,1] ]
]

function test(fn) {
  return function([spots, car, result]) {
    if (typeof result === 'boolean') return fn(spots, car) === result
    const [col0, row0] = result
    const [col, row] = fn(spots, car)
    return col0 === col && row0 === row
  }
}

console.log(cases.map(test(whereCanIPark)))

I’ve also encountered a failing test when submitting, with code that passed all tests when clicking β€œtest code”.

1 Like

Me too. It’s becoming usual these days.

const whereCanIPark = (spots, vehicle) => {
  const sizes = {
    M: 1,
    S: 2,
    R: 3
  }

  const v = vehicle[0].toUpperCase();
  for (let i = 0; i < spots.length; i++) {
    for (let j = 0; j < spots[i].length; j++) {
      const currentSpot = spots[i][j];
      if (sizes[currentSpot] && sizes[currentSpot] >= sizes[v])
        return [j, i];
    }
  }
  return false;  
}

Getting an issue where it passes all the test cases when you test the code, but fails when you submit it

I did this

const whereCanIPark = (spots, vehicle) => {
  let options = { regular: 'R', small: 'RS', motorcycle: 'RSM' }
  for (let i=0; i<spots.length;i++) 
    for (let j=0; j<spots[i].length;j++) 
      if (options[vehicle].includes(spots[i][j])) {
        return [j,i]
      }
  return false;
}
5 Likes

A tiny 113-character solution thanks to Array#findIndex and boolean shenanigans:

whereCanIPark=(s,v)=>{for(y in s)if(x=~s[y].findIndex(p=>p<"Z"&(v<"r"|v>"s"&p>"M"|p=="R")))return[~x,y];return!1}
1 Like

Update: The submission testing has since been fixed, and all appears to be functioning accordingly.

Details of Error/Bug (During Submit Code)

Test Results:

You have 1 Failing Test.

Failed: The whereCanIPark function returns a correct available spot

Reason: Your code ran but did not produce the correct result.

Hint: Make sure that you check the appropriate spots for the particular vehicle type

The Corresponding Test's Log:

Running test: The whereCanIPark function returns a correct available spot

spots [[β€œs”,β€œs”,β€œs”,β€œs”,β€œs”,β€œs”],[β€œs”,β€œM”,β€œs”,β€œS”,β€œr”,β€œs”],[β€œs”,β€œM”,β€œs”,β€œS”,β€œr”,β€œs”],[β€œS”,β€œr”,β€œs”,β€œm”,β€œr”,β€œs”],[β€œS”,β€œr”,β€œs”,β€œm”,β€œR”,β€œs”],[β€œS”,β€œr”,β€œS”,β€œM”,β€œM”,β€œS”]]

vehicle: regular

Returning [β€œ4”,β€œ4”]


spots [[β€œr”,β€œs”,β€œs”,β€œs”,β€œR”,β€œs”],[β€œs”,β€œr”,β€œs”,β€œs”,β€œR”,β€œm”],[β€œs”,β€œs”,β€œs”,β€œS”,β€œR”,β€œm”],[β€œs”,β€œr”,β€œs”,β€œM”,β€œR”,β€œM”],[β€œs”,β€œR”,β€œs”,β€œm”,β€œR”,β€œs”],[β€œS”,β€œr”,β€œs”,β€œM”,β€œM”,β€œs”]]

vehicle: small

Returning [β€œ4”,β€œ0”]

Seems like the X and Y coordinates are interchanged in tests??

So is it still broken? passed all the test but i cant submit

The x & y coordinates are indeed reversed: Here is the assert for the last test case:

      const spots = [
        ['s', 's', 's', 'S', 'R', 'M'],
        ['s', 'M', 's', 'S', 'R', 'M'],
        ['s', 'M', 's', 'S', 'R', 'm'],
        ['S', 'r', 's', 'm', 'R', 'M'],
        ['S', 'r', 's', 'm', 'R', 'M'],
        ['S', 'r', 'S', 'M', 'M', 'S']
      ]

      const vehicle = 'regular'

      const result = whereCanIPark(spots, vehicle)

      const stringResult = result[0] + "_" + result[1]

      const possibleAnswers = [
        "4_0", "1_4", "2_4", "3_4", "4_4"
      ]
      const isOneOfTheRightAnswers = possibleAnswers.includes(stringResult)
3 Likes

my answer:

const generateSpotValidator = vehicle => {
  switch(vehicle){
  case "regular": return spot => spot === "R";
  case "small": return spot => spot === "R" || spot === "S";
  case "motorcycle": return spot => spot === "R"||spot === "S"|| spot === "M";
  default: return () => false
  }
};

const whereCanIPark = (spots, vehicle) => {
  const index = spots.flat().findIndex(generateSpotValidator(vehicle));
  const l = spots[0].length;
  return index === -1? false: [ index % l, Math.floor(index / l) ];
}

@Tim-Lighthouse-Labs Is there a bug in the testing and submit code?

Change your output to [y,x]. That is how it is expecting the result I believe. I just submitted almost the same code as yours.

1 Like

coordinates are reversed indeed, changing [x,y] to [y,x] did the trick for me

I don’t think that is correct. My column in X and Y is the row.

38

Tried reversing it. it didn’t pass the test.

Some of the test cases have reversed coordinates, but not all.

For what it’s worth, I just clicked β€œSubmit” with it returning [x, y] and it worked, so it might just be the example tests that are borked.

3 Likes