Skip to content

Instantly share code, notes, and snippets.

@quinnlas
Last active April 24, 2023 23:41
Show Gist options
  • Save quinnlas/1667fc91331dcc1fbf226b713961f0cb to your computer and use it in GitHub Desktop.
Save quinnlas/1667fc91331dcc1fbf226b713961f0cb to your computer and use it in GitHub Desktop.
What does this function do?
const fn = (n, a = [[], '']) => n in a ? !!a[n] : (a.push(...a), fn(n, a))
@quinnlas
Copy link
Author

quinnlas commented Apr 3, 2023

Hint 1: Formatted code:
function fn (n, a = [[], '']) {
  if (n in a) {
    return !!a[n]
  } else {
    a.push(...a)
    return fn(n, a)
  }
}
Hint 2:

Remember the difference between in and of.

Hint 3:

The function is meant to be called with 1 parameter, a number. Try some examples to see what the output is.

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