Q:

Write a JavaScript program to find whether the members of a given array of integers is a permutation of numbers from 1 to a given integer

0

Write a JavaScript program to find whether the members of a given array of integers is a permutation of numbers from 1 to a given integer.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

function is_permutation(input_arr, n) {
    for (var i = 0; i < n; i++) {
        if (input_arr.indexOf(i + 1) < 0) 
          return false;
    }
    return true;
}
console.log(is_permutation([1, 2, 3, 4, 5], 5));
console.log(is_permutation([1, 2, 3, 5], 5));

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now