Skip to content

Instantly share code, notes, and snippets.

@pinkhominid
Last active April 22, 2020 03:16
Show Gist options
  • Save pinkhominid/5189f59745195df1e71aa21864f90ff9 to your computer and use it in GitHub Desktop.
Save pinkhominid/5189f59745195df1e71aa21864f90ff9 to your computer and use it in GitHub Desktop.
findSpliceUndo()
// 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