JavaScript Coding Examples
JavaScript Coding Examples
Write a function that takes an array of integers and returns the sum of all
the even numbers. 2
Write a function that takes a string and returns the reversed version of the
string. 3
Write a function that takes an array of strings and returns the longest string
in the array. 3
Write a function that takes a string and returns the number of vowels in the
string. 4
Write a function that takes an array of integers and returns the second
largest number in the array. 5
Write a function that takes an array of integers and returns a new array with
only the unique numbers. 6
Write a function that takes a string and returns true if the string is a
palindrome and false if it is not. 6
Write a function that takes an array of integers and returns the average of
the numbers. 7
Write a function that takes two arrays of integers and returns a new array
with only the numbers that are in both arrays. 8
}
}
return sum;
}
console.log(sumOfEvenNumbers([1, 2, 3, 4, 5, 6])); //
Output: 12
This function uses a for loop to iterate through the array of
integers. If a number is even, it adds it to the sum.
}
return longest;
}
console.log(uniqueNumbers([1, 2, 3, 3, 4, 4, 5])); //
Output: [1, 2, 3, 4, 5]