Advertisement
dubbie

A day difference v2

Dec 1st, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Old Code
  2. const newMap = e.props.map;
  3.  
  4. let arr = this.state.maps;
  5. let i = 0;
  6. let found = false;
  7.  
  8. while (!found && i < arr.length) {
  9.   found = arr[i].name === newMap.name;
  10.   i++;
  11. }
  12.  
  13. if (found) {
  14.     arr[i - 1].completed = !arr[i - 1].completed;
  15. }
  16.  
  17. this.setState({
  18.    maps: arr
  19. });
  20.  
  21. // New Code
  22. const items = this.state.maps;
  23. changedMaps.forEach(map => {
  24.     const i = items.map(m => m.name).indexOf(map.name);
  25.     items[i].completed = !items[i].completed;
  26. });
  27. this.setState({ items });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement