6 kyu

Get Password from grid

309 of 764kodejuice

Description:

In this kata you are expected to recover a scattered password in a (m x n) grid (you'll be given directions of all password pieces in the array)

The array will contain pieces of the password to be recovered, you'll get directions on how to get all the the pieces, your initial position in the array will be the character "x".

Heres what the array looks like

[
  ["p", "x", "m"],
  ["a", "$", "$"],
  ["k", "i", "t"]
]

The given directions would consist of [left, right, up, down] and [leftT, rightT, upT, downT], the former would be used to move around the grid while the latter would be used when you have a password to that direction of you.( E.g if you are in a position and the move to make is leftT it means theres a password to the left of you, so take the value and move there)

So in the 2d array example above, you will be given the directions ["lefT", "downT", "rightT", "rightT"], making for the word "pa$$".

Remember you initial position is the character "x".

So you write the function getPassword(grid, directions) that uses the directions to get a password in the grid.

Another example.

grid = [
  ["a", "x", "c"],
  ["g", "l", "t"],
  ["o", "v", "e"]
];

directions = ["downT", "down", "leftT", "rightT", "rightT", "upT"]

getPassword(grid, directions) // => "lovet"

Once again, Your initial position is the character "x", so from the position of "x" you follow the directions given and get all pieces in the grid.

Logic
Arrays
Algorithms
Data Structures

Similar Kata:

Stats:

CreatedApr 19, 2017
PublishedApr 19, 2017
Warriors Trained1417
Total Skips26
Total Code Submissions3517
Total Times Completed764
JavaScript Completions309
PHP Completions93
Python Completions364
Ruby Completions35
Total Stars29
% of votes with a positive feedback rating94% of 203
Total "Very Satisfied" Votes181
Total "Somewhat Satisfied" Votes18
Total "Not Satisfied" Votes4
Total Rank Assessments11
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • kodejuice Avatar
  • smile67 Avatar
  • KenKamau Avatar
  • hobovsky Avatar
  • saudiGuy Avatar
  • PetitLu117 Avatar
  • AmirTallap Avatar
Ad