Skip to content

Instantly share code, notes, and snippets.

const height = (node) => node ? Math.max(height(node.left), height(node.right)) + 1 : 0
// That's all folks!
return leftHeight > rightHeight ? leftHeight + 1 : rightHeight + 1
function height (node) {
if (!node) {
return 0
}
var leftHeight = height(node.left)
var rightHeight = height(node.right)
if (leftHeight > rightHeight) {
return leftHeight + 1 // Adding 1 for considering node's height
} else {
return rightHeight + 1
const rootNode = {
left: anotherNode,
right: yetAnotherNode,
value: 5,
}
@pratyushcrd
pratyushcrd / curry.js
Created August 14, 2017 07:41
One line curry function in Javascript ES6
const curry = (fn, arr = []) => (...params) => (arr.length + params.length >= fn.length) ? fn(...[...arr, ...params]) : curry(fn, [...arr, ...params])
/* Testing with a sum function */
const sum = curry(function (a, b, c, d, e) {
return a + b + c + d + e
})
console.log(sum(1, 2, 3, 4, 5)) // 15
console.log(sum()()(1)()(2)()(3, 4)(5)) // 15
console.log(sum(1, 2, 3)()()()(4, 5)) // 15
import random
num = random.randrange(0, 10)
while True:
str = input("guess between 0 to 9 or type exit ")
if str == "exit":
break
if not(str.isalnum()):
print("not a valid input ")
continue