Skip to content

Remove-Redundant-Slice-Index

Sourcery rule id: remove-redundant-slice-index

Description

Remove a redundant index from the array .slice() method.

Before

const toEnd = numbers.slice(3, numbers.length)

After

const toEnd = numbers.slice(3)

Explanation

Parameters in the array prototype .slice(start, end) method are optional, and by convention you should only use the necessary ones, to simplify readability. The end is not necessary if you want to slice to the end of the array. The start is additionally not necessary if you want to slice from the start of the array.