Created
February 1, 2022 09:27
-
-
Save hasangenc0/e7685d1a7c6a3221ea09b3e4c92a7eba to your computer and use it in GitHub Desktop.
Directions_Reduction.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function dirReduc(arr: string[]): string[] { | |
let result = []; | |
let mtrx: any = { | |
"NORTH": "SOUTH", | |
"SOUTH": "NORTH", | |
"WEST": "EAST", | |
"EAST": "WEST" | |
} | |
for (let val of arr) { | |
if(result.length > 0 && result[result.length - 1] === mtrx[val]) { | |
result.pop(); | |
} else { | |
result.push(val); | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment