---
id: 68b7687dded630607aceccad
title: "Challenge 46: 2nd Largest"
challengeType: 28
dashedName: challenge-46
---

# --description--

Given an array, return the second largest distinct number.

# --hints--

`secondLargest([1, 2, 3, 4])` should return `3`.

```js
assert.equal(secondLargest([1, 2, 3, 4]), 3);
```

`secondLargest([20, 139, 94, 67, 31])` should return `94`.

```js
assert.equal(secondLargest([20, 139, 94, 67, 31]), 94);
```

`secondLargest([2, 3, 4, 6, 6])` should return `4`.

```js
assert.equal(secondLargest([2, 3, 4, 6, 6]), 4);
```

`secondLargest([10, -17, 55.5, 44, 91, 0])` should return `55.5`.

```js
assert.equal(secondLargest([10, -17, 55.5, 44, 91, 0]), 55.5);
```

`secondLargest([1, 0, -1, 0, 1, 0, -1, 1, 0])` should return `0`.

```js
assert.equal(secondLargest([1, 0, -1, 0, 1, 0, -1, 1, 0]), 0);
```

# --seed--

## --seed-contents--

```js
function secondLargest(arr) {

  return arr;
}
```

# --solutions--

```js
function secondLargest(arr) {
  const unique = [...new Set(arr)];
  unique.sort((a, b) => b - a);
  return unique[1];
}
```
