Modify ↓
Ticket #4188 (closed enhancement: fixed)
.get(-n)
| Reported by: | rkatic | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | 1.4 |
| Component: | core | Version: | 1.3.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
Enable use of negative numbers as argument.
get: function( num ) {
...
return this[ num < 0 ? this.length + num : num ];
}
Change History
comment:1 in reply to: ↑ description ; follow-up: ↓ 2 Changed 4 years ago by rkatic
comment:2 in reply to: ↑ 1 ; follow-up: ↓ 3 Changed 4 years ago by rkatic
An alternative and more optimized solution of eq(n) would be:
eq: function( i ) {
return this.pushStack( this.get(i), 'eq', i )
}
comment:3 in reply to: ↑ 2 Changed 4 years ago by rkatic
This last solution is not enough to handle the "out of range" case and when value is not true. So forget it.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.

eq: function( i ) { return i == -1 ? this.slice( i ) : this.slice( i, +i + 1 ); },