A design-token audit lists the pixel spacings used on a page in spacings. The team wants the largest base unit that every spacing is a whole multiple of.
Write sharedSpacingUnit(spacings) that returns the greatest common divisor of all the numbers in spacings.
Input: spacings = [8,12,20] Output: 4
8, 12, and 20 are all multiples of 4, and no larger number divides all three.
Input: spacings = [16] Output: 16
With one spacing, the unit is the spacing itself.
1 <= spacings.length <= 10^51 <= spacings[i] <= 10^12Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #635 Shared Spacing Unit. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.