Created
November 24, 2017 11:54
-
-
Save knjname/bc1905078cbe742d3d2ae0d75ea8da50 to your computer and use it in GitHub Desktop.
前要素と比較してぶったぎる関数
This file contains hidden or 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
| export function partitionByComparingPredecessor<T>( | |
| list: T[], partition: (prev: T, cur: T) => boolean | |
| ): T[][] { | |
| const result: T[][] = [] | |
| let prev: T = null | |
| let accum: T[] = [] | |
| for (const cur of list) { | |
| if (prev !== null) { | |
| if (partition(prev, cur)) { | |
| result.push(accum) | |
| accum = [] | |
| } | |
| } | |
| prev = cur | |
| accum.push(cur) | |
| } | |
| if (accum.length > 0) { | |
| result.push(accum) | |
| } | |
| return result | |
| } | |
Author
knjname
commented
Dec 19, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment