Last active
March 15, 2020 03:11
-
-
Save r0bchain/79ffba699231a8c19988dd2eec641f58 to your computer and use it in GitHub Desktop.
Create and array with pairs of arrays (create subarrays with pairs).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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