Tests:
  • off Arrays with Reducer

    x
     
    const offArrays = obj => Object.keys(obj).reduce((off, key) => (obj[key] instanceof Array) ? off : (obj[key] instanceof Object) ? { ...off, [key]: offArrays(obj[key]) } : { ...off, [key]: obj[key] }, {})
    let objeto = {
        a: 1,
      b: [2,3],
      c: 4,
      d: {
        e: 5,
        f: {
            g: 6,
          h: [7, 8]
        },
        i: [9, 10],
        j: 11
      },
      k: {
        l: [12,13]
      },
      m: 14
    }
    console.log(offArrays(objeto))
  • off arrays with Linear

     
    const withoutArrays = obj => {
        if (!(obj instanceof Object)) return obj
        if (!(obj instanceof Array)) {
        let result
        for (const prop in obj) {
            const out = withoutArrays(obj[prop])
          if (out !== undefined) result = { ...result, [prop]: out }
        }
        return result
      }
      return undefined
    }
    let objeto = {
        a: 1,
      b: [2,3],
      c: 4,
      d: {
        e: 5,
        f: {
            g: 6,
          h: [7, 8]
        },
        i: [9, 10],
        j: 11
      },
      k: {
        l: [12,13]
      },
      m: 14
    }
    console.log(withoutArrays(objeto))
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    off Arrays with Reducer
    off arrays with Linear

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 4 years ago)
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:82.0) Gecko/20100101 Firefox/82.0
Firefox 82 on Ubuntu
View result in a separate tab
Test name Executions per second
off Arrays with Reducer 13170.7 Ops/sec
off arrays with Linear 13419.9 Ops/sec