---
id: 69e2383af7832c8032603b92
title: "Challenge 276: Offending Element"
challengeType: 28
dashedName: challenge-276
---

# --description--

Given an array of integers that is sorted in ascending order except for one out-of-place element, return the index of that element.

- If more than one element could be considered out of place, return the index of the first one.

# --hints--

`findOffender([1, 6, 2, 3, 4, 5])` should return `1`.

```js
assert.equal(findOffender([1, 6, 2, 3, 4, 5]), 1);
```

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

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

`findOffender([2, 1])` should return `0`.

```js
assert.equal(findOffender([2, 1]), 0);
```

`findOffender([2, 4, 1, 6, 8])` should return `2`.

```js
assert.equal(findOffender([2, 4, 1, 6, 8]), 2);
```

`findOffender([5, 18, 24, 33, 40, 55, 15, 68, 84, 91])` should return `6`.

```js
assert.equal(findOffender([5, 18, 24, 33, 40, 55, 15, 68, 84, 91]), 6);
```

# --seed--

## --seed-contents--

```js
function findOffender(arr) {

  return arr;
}
```

# --solutions--

```js
function findOffender(arr) {
  for (let i = 0; i < arr.length; i++) {
    const without = [...arr.slice(0, i), ...arr.slice(i + 1)];
    if (without.every((n, j) => j === 0 || without[j - 1] <= n)) return i;
  }
}
```
