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()...
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 :).
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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?
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 :).