Juno_okyo

CodeFights solutions

Jan 19th, 2015
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  /*
  2.  * A perfect array is an array in which
  3.  * each element is equal to the length of the array
  4.  *
  5.  * @Input: array of integers
  6.  * @Output:
  7.  * true if @Input is a perfect array,
  8.  * false otherwise
  9.  *
  10.  * @Example:
  11.  * for [2, 2] output should be true
  12.  * for [4, 4, 4] or [2, 1] output should be false
  13.  */
  14. function perfectArray(array) {
  15.  
  16.   for (var i = 0; i < array.length; i++) {
  17.     if (i !== array.length) { // Change i to array[i]
  18.       return false;
  19.     }
  20.   }
  21.   return true;
  22. }
Add Comment
Please, Sign In to add comment