Say I have an object like this:

```
{
  visited: true,
  value: 1,
  children: [
    {
      visited: true,
      value: 2,
      children: [
        {
          visited: true,
          value: 5,
          children: []
        },
        {
          visited: false,
          value: 6,
          children: []
        },
        {
          visited: false,
          value: 7,
          children: []
        },
      ]
    },
    {
      visited: false,
      value: 3,
      children: []
    },
    {
      visited: false,
      value: 4,
      children: []
    },
  ]
}

```

Is there a easy way traverse this without using any JS frameworks to finally return 3 ?

I have written a recursive function to check for objects with {visited: true} in each level and then drill down further until I hit a visited node with no children. I was just wondering if there is any optimization I could apply to this??