Hi!
I just did Grade School and my add ended up like 20lines long, with a filter and reduce! 🤯
I reviewed the community solutions and I noticed that pretty much none of them would handle adding the same student to the same grade twice, ie: test #11: Most dont remove dups in the grade roster, they just blindly add.
This caused me to poke into this test further and I found that the current "example" solution:
|
def add(db, name, grade) do |
|
if name in List.flatten(Map.values(db)) do |
|
db |
|
else |
|
Map.update(db, grade, [name], &[name | &1]) |
|
end |
|
end |
is deficient when the order of adds in this test is reverse (and why my attempt is so long!):
|
test "a student cannot be added to more than one grade" do |
|
actual = |
|
@db |
|
|> School.add("Aimee", 2) |
|
|> School.add("Aimee", 1) |
|
|
|
assert actual == %{2 => ["Aimee"]} |
|
end |
I'd like to:
- duplicate this test but with the
add order reversed
- update the "example", though maybe after someone reviews my solution! there has got to be a better one?!? 😁
Should I continue this?
thx!! << q
Hi!
I just did Grade School and my
addended up like 20lines long, with afilterandreduce! 🤯I reviewed the community solutions and I noticed that pretty much none of them would handle adding the same student to the same grade twice, ie: test #11: Most dont remove dups in the grade roster, they just blindly add.
This caused me to poke into this test further and I found that the current "example" solution:
elixir/exercises/practice/grade-school/.meta/example.ex
Lines 2 to 8 in 1a1cec4
is deficient when the order of
adds in this test is reverse (and why my attempt is so long!):elixir/exercises/practice/grade-school/test/school_test.exs
Lines 20 to 27 in 1a1cec4
I'd like to:
addorder reversedShould I continue this?
thx!! << q