CoDEVIANT #24 — Apples Falling from the Binary Tree

Mmmm…sweet, candy red apples…
You can visit any apple-tree (node), as often as you like, but you can’t pick up an apple that is already retrieved.
class BinaryTree {
constructor(value) {
this.value = value;
this.left = null;
this.right = null;
}
}
function nodeDepths(root) {
let depthCount = 0
return helper(root, depthCount)
}
function helper(node, counter) {
if(!node) {
return 0
}
let numbah = counter + helper(node.right, counter + 1) + helper(node.left, counter + 1)
return numbah
}
class BinaryTree {
constructor(value) {
this.value = value
this.left = null
this.right = null
}
}
function nodeDepths(root) {
let depthCount = 0
return helper(root, depthCount)
}
function helper(node, counter) {
if(!node) {
return 0
}
let numbah = counter + helper(node.right, counter + 1) + helper(node.left, counter + 1)
return numbah
}
Yay recursion!
How’d you like dem apples?

--

--

--

is a web developer, opera singer, actor, and lover of cats. (adrian-rosales.tech)

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Understanding The Browser Object Model in JavaScript

Teacher.

We have lift off — Rocket Loader GA is mobile!

10 Things Every Nest.js Developer Should Know

Improving SSR data loading

Using fetch() in 2019

Using Masonry.js in Nuxt

Serverless Rust with Cloudflare Workers

React + Router + Redux and Server Side Rendering

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Adrian Rosales

Adrian Rosales

is a web developer, opera singer, actor, and lover of cats. (adrian-rosales.tech)

More from Medium

Mentoring the Youth-Element

Time Efficiency of Sorting Algorithms

Launching 🚀🚀 … Resilient Huddle: the Software Security Strategy & Design Workshop for Startups

How to Setup Chroot SFTP in Linux (Allow only SFTP, not SSH)