Today's challenge comes from aryan-firouzian on Codewars. You are to figure out how many people are on the bus given the following scenario:
The...
For further actions, you may consider blocking this person and/or reporting abuse
JS:
Nice one, although you're missing the second argument to
reduce
which specifies the initial value fora
.According to the MDN Web Docs, that argument is optional.
Right :)
Rust Solution
This also checks to make sure that more people don't get off the stop than were on + got on that stop. This assumes no passengers were on the bus initially.
PHP 7.4:
BTW, it seems today's post didn't make it into the series.
Update: It's been fixed.
Ruby 2.6
Elixir:
CSS (kind of):
For the list of of integer arrays, we can use an actual HTML list with
<li>
that contain CSS variables with the number of people going up (--up
) and down (--down
) the bus. Then using CSS counters we can keep a count of the people who are on the bus at each moment.Live demo on CodePen.
Didn't see anyone else try it in C, so here's my solution in C:
Python:
JS
R
Here is the simple solution with Python:
Haskell
Smalltalk --- because it seems nobody did it yet:
Haskell:
My solution in js