1
0
forked from Mirror/wren

List; add remove(value)

Having to encode this behaviour at every call site is tedious. It makes a lot of sense to just have the method available on list itself.
This commit is contained in:
ruby0x1
2021-04-03 19:55:42 -07:00
parent 4d1d0d972e
commit ecce1f6be9
4 changed files with 61 additions and 3 deletions

View File

@ -0,0 +1,18 @@
var a = [1, 2, 3]
a.remove(2)
System.print(a) // expect: [1, 3]
var b = [1, 2, 3]
b.remove(1)
System.print(b) // expect: [2, 3]
var c = [1, 2, 3]
c.remove(3)
System.print(c) // expect: [1, 2]
// Return the removed value.
System.print([3, 4, 5].remove(4)) // expect: 4
System.print([3, 4, 5].remove(5)) // expect: 5
// Return null when not found
System.print([1, 2, 3].remove(8)) // expect: null