Skip to content

Instantly share code, notes, and snippets.

@madeleine68
Created September 4, 2021 06:01
Show Gist options
  • Save madeleine68/7f75f1c597c85b1e21572da186978da4 to your computer and use it in GitHub Desktop.
Save madeleine68/7f75f1c597c85b1e21572da186978da4 to your computer and use it in GitHub Desktop.
const whereCanIPark = function (spots, vehicle) {
let coordinates = false;
for(i = 0; i < spots.length; i++) {
for(j = 0; j < spots[i].length; j++) {
if(vehicle === 'regular') {
if(spots[i][j] === 'R') {
coordinates = [j,i];
break;
}
} else if (vehicle === 'small') {
if(spots[i][j] === 'S' || spots[i][j] === 'R') {
coordinates = [j,i];
break;
}
} else {
if(spots[i][j] === 'S' || spots[i][j] === 'MS' || spots[i][j] === 'R') {
coordinates = [j,i];
break;
}
}
}
}
return coordinates;
};
console.log(whereCanIPark(
[
// COLUMNS ARE X
// 0 1 2 3 4 5
['s', 's', 's', 'S', 'R', 'M'], // 0 ROWS ARE Y
['s', 'M', 's', 'S', 'r', 'M'], // 1
['s', 'M', 's', 'S', 'r', 'm'], // 2
['S', 'r', 's', 'm', 'r', 'M'], // 3
['S', 'r', 's', 'm', 'r', 'M'], // 4
['S', 'r', 'S', 'M', 'M', 'S'] // 5
],
'regular'
));
console.log(whereCanIPark(
[
['M', 'M', 'M', 'M'],
['M', 's', 'M', 'M'],
['M', 'M', 'M', 'M'],
['M', 'M', 'r', 'M']
],
'small'
));
console.log(whereCanIPark(
[
['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']
],
'motorcycle'
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment