# DGM Interview with Solehjon ## Invert the case of a string. Given a function: ```typescript invertChar = (char: string): string => char === char.toLowerCase() ? char.toUpperCase() : char.toLowerCase() ``` write a one-line function to invert the case of a string: // abCdE => ABcDe ```typescript invertString = (str: string): string => str.split('').map(char => invertChar(char)).join('') ``` ## Given a list of strings, return a single string of the first character of each string in the array. ```typescript const firstChars = (a: string[]): string => a.map(str => str[0]).join('') // ['h', 'w'] let firstCharsStr = "" for (let i = 0; i < a.length; i++) { firstCharsStr += a[i][0] } return firstCharsStr }; ``` ### Test Cases ```javascript firstChars(["hello", "world"]) === "hw"; ``` ## Fix the bugs in this function to count reachable nodes in a directed graph. ```typescript type Node<T> = { value: T, children: Node<T>[], } const countNodes<T> = (seen: Node<T>[]) => (root: Node<T>): number => if (root.children.length == 0) { return 1; } root.children .filter(node => !seen.contains(node)) .map((node) => countNodes([...seen, root])(node)) .reduce((sum, x) => sum + x, 1); ``` // ```javascript const plus = (x) => (y) => x + y; const plus1 = plus(1); plus1(2) == 3; ``` ## Given an array of numbers, return the greatest number without using sort. ```typescript const greatest = (ns: number[]): number => ns.reduce((maxValue, value) => max(maxValue, value), -INF); ``` ## Why doesn't 0.8 + 0.4 === 1.2? 0.5 + 0.5 == 1 0.25 + 0.25 === 0.5 0.9 + 0.25 3/4 1/3 0.3.. 0.8 = 8/10 = 4/5 1/2 1/4 0.1 + 0.25 0.8 1/4 => x * 2^(y), where x and y are integers ## Undo a b c d f f f t g h stack! state = { name: "hello", age: -10, } state.age = 1; dif0 = { name: "hello", age: -10, } dif1 = { age: 1, }