Skip to content

Instantly share code, notes, and snippets.

@davidhellsing
Last active December 15, 2017 13:11
Show Gist options
  • Save davidhellsing/01ecaecd4245441a81280310f7e847bc to your computer and use it in GitHub Desktop.
Save davidhellsing/01ecaecd4245441a81280310f7e847bc to your computer and use it in GitHub Desktop.

Revisions

  1. davidhellsing revised this gist Dec 15, 2017. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,5 @@
    findKey = (haystack, needle) => {
    let found = false
    let prop
    const iterate = (obj) => (
    Object.keys(obj).forEach((key) => {
    if (found === false) {
  2. davidhellsing revised this gist Dec 15, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -6,8 +6,8 @@ findKey = (haystack, needle) => {
    if (found === false) {
    if (key === needle) {
    found = key
    } else if (prop && typeof prop === 'object') {
    iterate(prop)
    } else if (obj[key] && typeof obj[key] === 'object') {
    iterate(obj[key])
    }
    }
    })
  3. davidhellsing revised this gist Dec 15, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -12,8 +12,8 @@ findKey = (haystack, needle) => {
    }
    })
    )
    if (payload && typeof payload === 'object') {
    iterate(payload)
    if (haystack && typeof haystack === 'object') {
    iterate(haystack)
    }
    return found
    }
  4. davidhellsing created this gist Dec 15, 2017.
    20 changes: 20 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    findKey = (haystack, needle) => {
    let found = false
    let prop
    const iterate = (obj) => (
    Object.keys(obj).forEach((key) => {
    if (found === false) {
    if (key === needle) {
    found = key
    } else if (prop && typeof prop === 'object') {
    iterate(prop)
    }
    }
    })
    )
    if (payload && typeof payload === 'object') {
    iterate(payload)
    }
    return found
    }
    }