Skip to content

Instantly share code, notes, and snippets.

@r0bchain
Last active March 15, 2020 03:11
Show Gist options
  • Save r0bchain/79ffba699231a8c19988dd2eec641f58 to your computer and use it in GitHub Desktop.
Save r0bchain/79ffba699231a8c19988dd2eec641f58 to your computer and use it in GitHub Desktop.
Create and array with pairs of arrays (create subarrays with pairs).
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'pairs'
})
export class PairsPipe implements PipeTransform {
transform( arr: any[] ): any[] {
const pares = arr.reduce( (result, value, index, array) => {
if ( index % 2 === 0) {
result.push(array.slice(index, index + 2));
}
return result;
}, []);
return pares;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment