Created
June 9, 2023 07:46
-
-
Save psenger/0f0c1cde1cb7bf7005bb3b3acc455794 to your computer and use it in GitHub Desktop.
[Greedy Spy on next value] #Array #JavaScript
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
const pattern = 'abcdefgh'; | |
for (const [currentChar, nextChar] of pattern.split('').reduce((acc,value,idx,arr)=>{const entry = [value]; if ( arr.length > idx + 1 ) entry.push(arr[idx+1]); acc.push(entry); return acc},[])) { | |
console.log(currentChar,nextChar) | |
} | |
/** | |
a b | |
b c | |
c d | |
d e | |
e f | |
f g | |
g h | |
h undefined | |
**/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment