Skip to content

W.TakeRight #20

@rc1

Description

@rc1
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'] );
    } );
} );

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions