Skip to main content
1 of 5
ospahiu
  • 243
  • 1
  • 8

Same length sub arrays

Background:

Here's a little simple challenge. You want to be able to find out whether the arrays inside an array have the same length.

Input:

Your input should consist of exactly one array (this is the value passed to the function, not a user input). Your function takes exactly 1 parameter. It could contain arrays or be empty. No error checking needed, assume only list is ever passed in. Assume a 1-D array such as [1] or [1,2,3,4,5] is never passed in.

Output:

Return true if all the list elements have the same length, false if they don't, and null (or whatever your language equivalent is) if the list is empty. ###Some test cases:

List: [] - None
List: [[1], [1], [2]] - True
List: [[1]] - True
List: [[1, 2, 3, 4]] - True
List: [[1, 2, 3, 4, 5], [2], [12, 314123]] - False
List: [[1, 2, 3, 4], [1]] - False

No std(in/out) input/output needed, the function only needs to return boolean values true or false; or Null if the function is passed an empty list. Only one return value is returned.

Rules:

Shortest byte count wins, only function is necessary.

ospahiu
  • 243
  • 1
  • 8