Skip to content
Snippets Groups Projects
Commit c7049ed0 authored by Filipa Lacerda's avatar Filipa Lacerda Committed by Phil Hughes
Browse files

Adds documentation entry: Don't user forEach, aim for code without side effects

parent 9bef6ce6
No related branches found
No related tags found
No related merge requests found
Loading
@@ -168,6 +168,23 @@ See [our current .eslintrc][eslintrc] for specific rules and patterns.
Loading
@@ -168,6 +168,23 @@ See [our current .eslintrc][eslintrc] for specific rules and patterns.
   
- Avoid constructors with side-effects - Avoid constructors with side-effects
   
- Prefer `.map`, `.reduce` or `.filter` over `.forEach`
A forEach will cause side effects, it will be mutating the array being iterated. Prefer using `.map`,
`.reduce` or `.filter`
```javascript
const users = [ { name: 'Foo' }, { name: 'Bar' } ];
// bad
users.forEach((user, index) => {
user.id = index;
});
// good
const usersWithId = users.map((user, index) => {
return Object.assign({}, user, { id: index });
});
```
   
#### Parse Strings into Numbers #### Parse Strings into Numbers
- `parseInt()` is preferable over `Number()` or `+` - `parseInt()` is preferable over `Number()` or `+`
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment