← Back to challenges

Recursion: Isolated or Grouped?

JavaScriptHardrecursionarrays

Instructions

Write a function that extracts the max value of a number in an array. If there are two or more max values, return it as an array, otherwise, return the number. This process could be relatively easy with some of the built-in Array functions, but the required approach is recursive.

Examples

isoGroup([31, 7, 2, 13, 7, 9, 10, 13]) ➞ 31

isoGroup([1, 3, 9, 5, 1, 7, 9, -9]) ➞ [9, 9]

isoGroup([97, 19, -18, 97, 36, 23, -97]) ➞ [97, 97]

isoGroup([-31, -7, -13, -7, -9, -13]) ➞ [-7, -7]

isoGroup([-1, -3, -9, -5, -1, -7, -9, -9]) ➞ [-1, -1]

isoGroup([107, 19, -18, 79, 36, 23, 97]) ➞ 107

Notes

  • You can read more about recursion if you aren't familiar with it yet or haven't fully understood the concept before taking up this challenge.
  • If you think recursion is fun, you can find a collection of those challenges here.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.