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

Learn Through Helping Each Other

4 Useful JavaScript ES2020 Features that You Should Know

JavaScript ES2020 Features.

JS Understanding Iteration protocols

Why we chose React Native for our mobile apps

Write Better Code in React

Experiences on JavaScript Workshop

How to Build Angular Document Scanner with Dynamsoft Web Capture SDK

Starting with Angular

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

UReach Hard Drive Erasers — Used Computer Recycling Made Easy

🎇Pay for Your Education in DSCPL Tokens!🎇

EDNS Message Function that Connects you with web3.0 World.

Increased backlash in Russia against anti-war musicians (meanwhile western bands play dead and…

Increased backlash in Russia against anti-war musicians (meanwhile western bands play dead and pretend there is no war)