-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
Description
export const takeRight = ( arr, number=1 ) => {
const start = Math.max( arr.length - number, 0 );
return arr.slice( start, start + number );
};
describe( 'takeRight', () => {
it( 'does not throw', () => {
takeRight( [], 0 );
} );
it( 'in retuns all when ask to return more', () => {
expect( takeRight( [ 1, 2, 3 ], 10 ) ).toEqual( [ 1, 2, 3 ] );
} );
it( 'returns the last 2', () => {
expect( takeRight( [1, 2, 3, 4, 5, 'hello'], 2 ) ).toEqual( [5, 'hello'] );
} );
} );