Happy Juneteenth! I love everyone's approaches here, it's fun to see the way each person thinks through the problem.
I'll be posting my answers on Monday (along with the next installment of With Only CSS) so encourage your friends to give this a shot over the weekend (or take another go yourself)!
Follow me and react with a 🔖 so you remember to come back and see what I post here.
Drop a 🦄 or ❤️ if you'd be interested in some follow up posts going more in depth into each (OO/FP) solution: how they work; how they are similar; and how they are different.
Thanks everyone who took the time to post a solution to my little challenge; I'll see you all on Monday!
Similar to Heiker's solution above; the main part of this solution is defining "true" and "false" as functions taking the same two parameters but returning one or the other.
Similarly to the functional approach; the main part of this solution is defining "true" and "false" as objects. But now instead of parameters, the objects have the same interface and return one or the other of the attributes set on the object.
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.
Happy Juneteenth! I love everyone's approaches here, it's fun to see the way each person thinks through the problem.
I'll be posting my answers on Monday (along with the next installment of With Only CSS) so encourage your friends to give this a shot over the weekend (or take another go yourself)!
Follow me and react with a 🔖 so you remember to come back and see what I post here.
Drop a 🦄 or ❤️ if you'd be interested in some follow up posts going more in depth into each (OO/FP) solution: how they work; how they are similar; and how they are different.
Thanks everyone who took the time to post a solution to my little challenge; I'll see you all on Monday!
As promised, here is my functional approach to solving this (deeper article on it to come soon)
Similar to Heiker's solution above; the main part of this solution is defining "true" and "false" as functions taking the same two parameters but returning one or the other.
You can see both solutions in action on this codepen (planning one final post doing a compare/contrast between the two approaches)
And here is my object-oriented approach (deeper article on it to come soon)
Similarly to the functional approach; the main part of this solution is defining "true" and "false" as objects. But now instead of parameters, the objects have the same interface and return one or the other of the attributes set on the object.