Last active
April 22, 2020 03:16
-
-
Save pinkhominid/5189f59745195df1e71aa21864f90ff9 to your computer and use it in GitHub Desktop.
findSpliceUndo()
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
// Find, Splice, Undo | |
function findSpliceUndo(arr, findCallback) { | |
const idx = arr.findIndex(findCallback) | |
if (idx < 0) return | |
const removedArr = arr.splice(idx, 1) | |
return () => arr.splice(idx, 0, removedArr[0]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment