Skip to content

writetome51/array-get-page

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

getPage<T>(
      pageNumber,
      itemsPerPage,
      array: T[]
): T[]

Paginates the data in array.
array is never modified.

Examples

let arr = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20];

console.log(getPage(1, 5, arr));
// --> [1,2,3,4,5]

console.log(getPage(2, 5, arr));
// --> [6,7,8,9,10]

console.log(getPage(1, 7, arr));
// --> [1,2,3,4,5,6,7]

console.log(getPage(3, 7, arr));
// --> [15,16,17,18,19,20]

console.log(getPage(4, 7, arr));
// --> 'Error: The requested page does not exist'

console.log(getPage(1, 19, arr));
// --> [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]

console.log(getPage(2, 19, arr));
// --> [20]

Installation

npm i @writetome51/array-get-page

Loading

import { getPage } from '@writetome51/array-get-page';

License

MIT

About

Javascript function that paginates an array.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published