Q:

Write a JavaScript program to check whether the first and last elements are equal of a given array of integers length 3

0

Write a JavaScript program to check whether the first and last elements are equal of a given array of integers length 3.

All Answers

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

function first_last_same(nums)
   {
    var end = nums.length - 1;
    if (nums.length >= 1){
       return nums[0] == nums[end];
    } else {return false;}
}

console.log(first_last_same([10, 20, 30])); 
console.log(first_last_same([10, 20, 30, 10])); 
console.log(first_last_same([20, 20, 20])); 

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