Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * A perfect array is an array in which
- * each element is equal to the length of the array
- *
- * @Input: array of integers
- * @Output:
- * true if @Input is a perfect array,
- * false otherwise
- *
- * @Example:
- * for [2, 2] output should be true
- * for [4, 4, 4] or [2, 1] output should be false
- */
- function perfectArray(array) {
- for (var i = 0; i < array.length; i++) {
- if (i !== array.length) { // Change i to array[i]
- return false;
- }
- }
- return true;
- }
Add Comment
Please, Sign In to add comment