Hackerrank DS Arrays in JS
One challenge I completed is the Hackerrank's Data Structure Arrays Challenge! The challenge is basically asking you to reverse an array of numbers. There are a few specifications to the challenge in order to properly solve the problem. My answer code is at the bottom of this post. This was the first challenge I solved on Hackerrank. I will analyze the code I have written and show the input and outputs from Hackerrank. The function reverseArray()
has a parameter of the predeclared variable of a. function reverseArray(a)
. In order to add the working specifications of the integer, one is greater than or equal to n and greater than or equal to 1000. JavaScript has a reverse function in order to reverse the content inside the element. A sample input was 1 4 3 2
. A reversed output would be 2 3 4 1
. The hardest input was 6676 3216 4063 8373 423 586 8850 6762
. My correct but long output was 6762 8850 586 423 8373 4063 3216 6676
. This is the end of my analysis and accomplishment of my first Hackerrank challenge!
function reverseArray(a) {
// Declare an array with numbers 1-10
var n = [1, 2, 3, 4, 5, 6, 7, 8, 9];
// Add specifications to the problem
1 <= n <= 1000;
// Reverse the array element's order
a.reverse();
// Return the reversed array
return a;
}