Skip to content

Instantly share code, notes, and snippets.

@hasangenc0
Created February 1, 2022 09:27
Show Gist options
  • Save hasangenc0/e7685d1a7c6a3221ea09b3e4c92a7eba to your computer and use it in GitHub Desktop.
Save hasangenc0/e7685d1a7c6a3221ea09b3e4c92a7eba to your computer and use it in GitHub Desktop.
Directions_Reduction.ts
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