# Algorithm Challenge: Mutations (Spoiler!)

**URL:** <https://forum.freecodecamp.org/t/algorithm-challenge-mutations-spoiler/85251>\
**Category:** General\
**Created:** [February 8, 2017, 5:39pm UTC](https://forum.freecodecamp.org/t/algorithm-challenge-mutations-spoiler/85251 "2017-02-08T17:39:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gr6](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/gr6/32/18439_2.png) [@gr6](https://forum.freecodecamp.org/u/gr6)\
**Post date:** [February 8, 2017, 5:39pm UTC](https://forum.freecodecamp.org/t/algorithm-challenge-mutations-spoiler/85251/1 "2017-02-08T17:39:47Z")

</div>

So, I think I’ve got this. But I’m confused about why one of these passes and why the other doesn’t…

> **This does not pass.**
>
> ```javascript
> function mutation(arr) {
> for (var i = 0; i < arr[1].length; i++) {
> if (arr[0].toLowerCase().indexOf(arr[1][i].toLowerCase()) < 0) {
> return false;
> } else {
> return true;
> }
> }
> }
> 
> ```

> **But this does.**
>
> ```javascript
> function mutation(arr) {
> for (var i = 0; i < arr[1].length; i++) {
> if (arr[0].toLowerCase().indexOf(arr[1][i].toLowerCase()) < 0)
> return false;
> }
> return true;
> }
> 
> ```

Why is this? I thought best practice was to include curly braces after your `if` statements.

---

<div class="post-metadata">

**Author:** ![jp89](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jp89/32/23164_2.png) [@jp89](https://forum.freecodecamp.org/u/jp89)\
**Post date:** [February 8, 2017, 6:41pm UTC](https://forum.freecodecamp.org/t/algorithm-challenge-mutations-spoiler/85251/2 "2017-02-08T18:41:54Z")

</div>

In the first case the only one iteration of the for loop is executed - note that if the condition in if statement is met function returns false - if not it returns true. Either way the function returns.

In the second case for loop may is executed until the if condition is met or until ‘i’ is \>= arr[1].length.  
Presumably more then one time.

Kind regards,  
Jarosław Pawlak

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 5:24pm UTC](https://forum.freecodecamp.org/t/algorithm-challenge-mutations-spoiler/85251/3 "2021-01-16T17:24:50Z")

</div>

Closed on January 16, 2021, 5:24pm UTC


