Jump to content

Category talk:Wren-seq: Difference between revisions

→‎Source code: Added 'replaceAll and 'toMap' methods to Lst class.
(→‎Source code: Added more methods to assist with initialization.)
(→‎Source code: Added 'replaceAll and 'toMap' methods to Lst class.)
Line 443:
}
return [old, swap]
}
 
// Removes all instances of 'value' from 'a'.
// Returns 'value' if there were any removals, otherwise 'null'.
static removeAll(a, value) {
isList_(a)
if (a.isEmpty) return null
var found = false
for (i in a.count-1..0) {
if (a[i] == value) {
a.removeAt(i)
found = true
}
}
return found ? value : null
}
 
// Return a map whose keys are 'k' and corresponding values 'v'
// where 'k' and 'v' are suitable lists.
static toMap(k, v) {
isList_(k)
isList_(v)
if (k.count != v.count) Fiber.abort("The number of keys and values must be the same.")
var m = {}
for (i in 0...k.count) m[k[i]] = v[i]
return m
}
 
9,485

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.