Skip to content

Files

Latest commit

 

History

History
29 lines (21 loc) · 584 Bytes

Performance-ArraySemiInfiniteRangeSlice.md

File metadata and controls

29 lines (21 loc) · 584 Bytes

Pattern: Missing use of Array#take/Array#drop

Issue: -

Description

Identifies places where slicing arrays with semi-infinite ranges can be replaced by Array#take and Array#drop.

Examples

# bad
# array[..2]
# array[...2]
# array[2..]
# array[2...]
# array.slice(..2)

# good
array.take(3)
array.take(2)
array.drop(2)
array.drop(2)
array.take(3)

Further Reading