# CommonEdge Interview with Mihajlo ### If you could program in any language, what would it be? ### Why doesn't 0.4 + 0.8 == 1.2? (in javascript, Java, PHP, C, etc.) - Floating point is not perfectly precise. - 1.2000000000000002 ### Fix the bugs in this function to count reachable nodes in a directed graph. ```php $node_names = array(); class Node { public $value; public $children; // count how many nodes are reachable from this node including this node public countNodes($seen=[]) { $n = 1; $seen[] = $this; foreach($this->children as $child) { if $child is contained in $seen then continue; $n += $child->countNodes($seen); $node_names[$child->name] = true; } return $n; } } ``` ### Given an array of numbers, return the second greatest number without using sort. ```php $arr = [2, 15, 48, 78, 22, 35] $arr = [0, 1, 1] $max = false; $max_pos = -1; for ($i = 0; $i < count($arr); $i++) { if ($max === false && $max < $arr[$i]) { $max = $arr[$i]; $max_pos = $i; } } $max2 = false; for ($i = 0; $i < count($arr); $i++) { if ($i != $max_pos && $max2 === false && $max2 < $arr[$i]) { $max2 = $arr[$i]; } } ``` ### Discuss advantages vs disadvantages of inlining vs calling out to library functions - that is, more complicated versions of ```javascript const max = a > b ? a : b; ``` vs. ```javascript const max = Math.max(a,b); ``` vs. ```javascript= const max = ourmax(a,b); ``` ### Discuss static type systems. ```typescript= const ourmax = (x: number, y: number): number => // ... ``` ```typescript= const somemysteryfunction = <A,B>(f: (x: A) => B, xs: A[]): B[] => // ... const calcSurface = (x: Opening): Surface => // very complicated const panalizeSurface = (x: Surface): Panels[] => // also complicated ```