Skip to content

Instantly share code, notes, and snippets.

@jgimbel
Last active August 2, 2017 21:52
Show Gist options
  • Save jgimbel/ef84e8652c5188d9c3131f1e9afdc351 to your computer and use it in GitHub Desktop.
Save jgimbel/ef84e8652c5188d9c3131f1e9afdc351 to your computer and use it in GitHub Desktop.
const lastNotNull = (arr) => arr[arr.length - 1] ? arr[arr.length - 1] : lastNotNull(arr.slice(0, -1))
const values = [1, 3, 5, 2, null, null]
console.log(lastNotNull(values))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment