79158954

Date: 2024-11-05 11:51:46
Score: 1
Natty:
Report link
import { Pipe, PipeTransform } from 
'@angular/core';

@Pipe({
  name: 'paginate'
})
export class PaginatePipe implements 
PipeTransform {

transform(value: any[], page: 
number, 
pageSize: number): any[] {
if (!Array.isArray(value) || page == 
null || pageSize == null) {
  return value;
}

// Calculate the starting index of 
the data slice
const startIndex = (page - 1) * Page 
size;

// Slice the data array to get the 
relevant page
return value.slice(startIndex, 
startIndex + pageSize);
}

}

Reasons:
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: user28143503