# Day 3

## Arrays

{% embed url="<https://www.hackerrank.com/challenges/js10-arrays/problem?isFullScreen=true>" %}

```javascript
/**
*   Return the second largest number in the array.
*   @param {Number[]} nums - An array of numbers.
*   @return {Number} The second largest number in the array.
**/
function getSecondLargest(nums) {
    // Complete the function
    let firstLargest = 0;
    let secondLargest = 0;
    for (let i = 0; i < nums.length; i++){
        if(nums[i] > firstLargest){
            secondLargest = firstLargest;
            firstLargest = nums[i];
        }
        if(nums[i] < firstLargest && nums[i] > secondLargest){
            secondLargest = nums[i];
        }            
    }
    return secondLargest;
}
```

## Try, Catch, and Finally

{% embed url="<https://www.hackerrank.com/challenges/js10-try-catch-and-finally/problem?isFullScreen=true>" %}

```javascript
/*
 * Complete the reverseString function
 * Use console.log() to print to stdout.
 */
function reverseString(s) {
    try{
        s = s.split('').reverse().join('');
    }
    catch(e){
        console.log(e.message);
    }
    finally{
        console.log(s);
    }
}
```

## Throw

{% embed url="<https://www.hackerrank.com/challenges/js10-throw/problem?isFullScreen=true>" %}

```javascript
/*
 * Complete the isPositive function.
 * If 'a' is positive, return "YES".
 * If 'a' is 0, throw an Error with the message "Zero Error"
 * If 'a' is negative, throw an Error with the message "Negative Error"
 */
function isPositive(a) {
    if(a > 0)
        return "YES";
    else if(a == 0)
        throw new Error("Zero Error");
    else
        throw new Error("Negative Error");
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dailyjournal.gitbook.io/solutions/hackerrank-solutions/tutorials/10-days-of-javascript/day-3.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
