-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLast survivor.js
More file actions
21 lines (18 loc) · 805 Bytes
/
Copy pathLast survivor.js
File metadata and controls
21 lines (18 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// You are given a string of letters and an array of numbers.
// The numbers indicate positions of letters that must be removed, in order, starting from the beginning of the array.
// After each removal the size of the string decreases (there is no empty space).
// Return the only letter left.
// Example:
// let str = "zbk", arr = [0, 1]
// str = "bk", arr = [1]
// str = "b", arr = []
// return 'b'
// Notes
// The given string will never be empty.
// The length of the array is always one less than the length of the string.
// All numbers are valid.
// There can be duplicate letters and numbers.
// If you like this kata, check out the next one: Last Survivors Ep.2
function lastSurvivor(letters, coords) {
return coords.reduce((x, y)=> x.slice(0, y) + x.slice(y+1), letters)
}