Is the modulo function used just to be difficult?


#1

The point of all of that code is just to say 1, 2, 3, 4. It seems to me there has to be a much clearer and simpler way to do this where the code would be much more readable. I understand the functions and how modulo works, it seems like it’s written this way just to be difficult. Is there some reason I’m not getting that it couldn’t be written more simply?


#2

what code? If you refer to code, including it can be very useful.

If this is an exercise, please also include exercise url


#3

https://www.codecademy.com/courses/react-102/lessons/container-presentational-components/exercises/container-presentational-components-apply

  nextGP() {
    let current = this.state.currentGP;
    let next = ++current % GUINEAPATHS.length;
    this.setState({ currentGP: next });
  }

  componentDidMount() {
    this.interval = setInterval(this.nextGP, 1000);
  }

  componentWillUnmount() {
    clearInterval(this.interval);
  }

#4

Why is this to complicated? I don’t see the problem, the modulo operator ensures that after we had all images in array, it goes back to the first image


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.