Skip to content

Instantly share code, notes, and snippets.

@digitalbase
Created September 21, 2021 08:39
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save digitalbase/cdfd2e3ff84ce9ea7354cf9bd970f8bf to your computer and use it in GitHub Desktop.
Save digitalbase/cdfd2e3ff84ce9ea7354cf9bd970f8bf to your computer and use it in GitHub Desktop.

Form interview

1. console.log

AAlter the behavior of console.log so that it will print not only the given values but also their types.

Example:

console.log(3); // 3 "number"
console.log("a"); // "a" "string"
console.log(2, "a"); // 2 "number" "a" "string"

2. Recursion

Implement getUniqueSortedNumbers(tree) function. It should return an array of unique number values in given tree object, sorted in ascending order. The type of the tree argument would be defined in TypeScript as:

type Tree = Record<string, number | Tree>;

Example:

getUniqueSortedNumbers({
  a: {
    x: 3,
    y: {
      d: 2,
      e: 2,
      f: {
        g: 4
      },
      z: 8
    }
  }
}); // [2, 3, 4, 8];
@OskarGasiorowski
Copy link

@digitalbase I think you should remove @menglu95 answers 😄

@menglu95
Copy link

My answers are incorrect? 🤔
cc: @digitalbase @OskarGasiorowski

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment