At [Contribution Guidelines](https://github.com/TheAlgorithms/Javascript/blob/master/CONTRIBUTING.md) have minimal side effects is one of What is an Algorithm. I think code can improve by refactor to functional programming.