DEV Community

Discussion on: This simple math hack lets you create an image carousel without any if statements

Collapse
 
andrearaujo profile image
André Araújo (Andrev) • Edited

Yeah, I wasn't saying it's wrong, and I know that the point of this post is to show the math, I just showed one of the possible solutions, but you confused me a little bit now...

What would be the difference in the pseudo-code below and why the second one wouldn't follow the DRY principle?

// some logics in the button...
carousel.handleImageChange('forward');
...
// some logics in the button...
carousel.handleImageChange('other direction');
...
// some logics in the button...
carousel.nextImage()
...
// some logics in the button...
carousel.prevImage()
...
Thread Thread
 
ranewallin profile image
Rane Wallin

Nothing wrong with it at all. My point was that you still have an if statement, it's just in a different place. The only way to eliminate it would be if there were two completely different button components, one for forward and one for back, that called different code, which would then be less dry. I wasn't saying there was anything wrong with what you posted :).