# JAVASCRIPT difficulty

Hi
I am currently learning javascript and I came across this exercise question:
```Code<html>
<body>
<script language="javascript">
var numbers = [-19, -7, -55, 78, 54, 60, -53, 35, 56, 42, 20, 77, 93, -41, -24, -60, 7, 86, 14, -99];

function secondLargest(num){
return 0;
}

function reverse(str){
return "";
}
</script>
</body>
</html>

The scenario is that I have to
Define a function secondLargest() that takes an array and returned the 2nd largest number.
AND
Define a function reverse() that computes the reversal of a string. For example, reverse("Hello world") should return the string "I love Javascript".
I have had done many attempts to solve the task but I run into problems.
Any help? it would be appreciated

#### Oleg

• Dec 5th, 2014

Here is it.

```Codevar numbers = [-19, -7, -55, 78, 54, 60, -53, 35, 56, 42, 20, 77, 93, -41, -24, -60, 7, 86, 14, -99];
function secondLargest(num){
var mn = num;
for(var i=1; i<num.length; i++)
if(mn < num[i])mn = num[i];
return mn;
}
function reverse(str){
var rstr = "";
for(var i=0; i<str.length; i++){
rstr = rstr + str.charAt(str.length - i -1);
}
return rstr;
}
```

#### Anshul

• Jul 1st, 2019

```Codevar numbers = [-19, -7, -55, 78, 54, 60, -53, 35, 56, 42, 20, 77, 93, -41, -24, -60, 7, 86, 92, 14, -99];

function secondLargest(num){

var first = num;
var second = num;

for(var i=1; i<num.length; i++)

if(first < num[i]){
second = first;
first = num[i];
}else{
if(second < num[i]){
second = num[i];
}
}

return second;
}

function reverse(str){

var rstr = "";

for(var i=0; i<str.length; i++){

rstr = rstr + str.charAt(str.length - i -1);

}

return rstr;

}

```  