Category talk:Wren-array: Difference between revisions

Added indexOf(value, start) method to all classes.
(→‎Source code: Added CharArray class.)
(Added indexOf(value, start) method to all classes.)
 
Line 66:
// Returns the index of 'value' in the current instance or -1 if 'value' is not found.
indexOf(value) { _a.indexOf(value) }
 
// As indexOf(value) method but starts the search from index 'start'. If 'start' is
// negative it counts backwards from the end of the array.
indexOf(value, start) {
if (count == 0) return -1
if (start < 0) start = count + start
if (start >= count) Fiber.abort("'start' is out of bounds.")
for (i in start...count) {
if (_a[i] == value) return i
}
return -1
}
 
// Returns the index of the last occurrence of 'value' in the current instance
Line 232 ⟶ 244:
for (i in _rng) if (this[i] == v) return i
return -1
}
 
// As indexOf(v) method but starts the search from index 'start'. If 'start' is
// negative it counts backwards from the end of the array.
indexOf(v, start) {
if (start < 0) start = count + start
if (start >= _rng.to) Fiber.abort("'start' is out of bounds.")
for (i in start..._rng.to) {
if (this[i] == v) return i
}
return -1
}
 
Line 407 ⟶ 430:
for (i in _rng) if (this[i] == v) return i
return -1
}
// As indexOf(v) method but starts the search from index 'start'. If 'start' is
// negative it counts backwards from the end of the array.
indexOf(v, start) {
if (start < 0) start = count + start
if (start >= _rng.to) Fiber.abort("'start' is out of bounds.")
for (i in start..._rng.to) {
if (this[i] == v) return i
}
return -1
}
 
Line 567 ⟶ 600:
Check.char("c", c, 0, 255)
return _a.indexOf(c.codePoints[0])
}
 
// As indexOf(c) method but starts the search from index 'start'. If 'start' is
// negative it counts backwards from the end of the array.
indexOf(c, start) {
Check.char("c", c, 0, 255)
return _a.indexOf(c.codePoints[0], start)
}
 
9,490

edits