Comments on Backspace an array
Parent
Backspace an array
+7
−0
Challenge
Given an array consisting of positive integers and 0s, return it with 0s acting like backspaces.
Leading backspaces do nothing, and more backspaces than elements also does nothing.
Credit: A comment on this video
Test Cases
[0,0,0,0,0,5,7] -> [5,7]
[1,2,0,3] -> [1,3]
[1,5,5,0,2,0,0,8] -> [1,8]
[1,2,3,4,0,0,9] -> [1,2,9]
[1,2,0,0,0,0,0] -> []
+3
−0
[Jelly], 6 bytes ṣ0Ṗ;¥/ …
3y ago
+3
−0
Scala, 45 bytes ```scala ./: …
3y ago
+1
−0
[JavaScript (Node.js)], 41 40 …
3y ago
+1
−0
[Python 3.8 (pre-release)], 62 …
3y ago
+0
−0
Japt, 9 bytes ô rÈÔÅÔcY …
3y ago
+0
−0
[Husk], 6 bytes Fo+hx0 …
3y ago
Post
+3
−0
Jelly, 6 bytes
ṣ0Ṗ;¥/
How it works
ṣ0Ṗ;¥/ - Main link. Takes a list on the left
ṣ0 - Split at zeroes
¥/ - Reduce by:
Ṗ - Remove the last element
; - Concatenate
1 comment thread