I had to stare at it for a few minutes to go through all the possibilities.
That's possibly because of lack of familiarity.
The Rust equivalent doesn't look that different to me:
fn categorize(mut sides: [T; 3]) -> Option<Category> { sides.sort_unstable_by(|a, b| a.partial_cmp(b).unwrap()); let [a, b, c] = sides; let is_triangle = a + b > c; if is_triangle { Some(match (a.eq(&b), b.eq(&c)) { (true, true) => Equilateral, (true, _) | (_, true) => Isoceles, _ => Scalene, }) } else { None } }
in particular
match (a.eq(&b), b.eq(&c)) { (true, true) => Equilateral, (true, _) | (_, true) => Isoceles, _ => Scalene, }
In Erlang (and Elixir is similar) something like (again, assuming that the sides are sorted by length so that equal sides will always be adjacent)
case Sides of {A, A, A} -> "equilateral"; {A, A, C} -> "isosceles"; {A, B, B} -> "isosceles"; _ -> "scalene" end.
or
case Sides of {A, B, C} when A == B andalso B == C -> "equilateral"; {A, B, C} when A == B orelse B == C -> "isosceles"; _ -> "scalene" end.
ReScript (aka ReasonML; JavaScript flavored OCaml)
let kind = switch (a === b, b === c) { | (true, true) => "equilateral" | (true, _) | (_ , true) => "isosceles" | _ => "scalene" }
etc.
very likely.
And nice overview, of how different languages handle the same problem
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
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.
That's possibly because of lack of familiarity.
The Rust equivalent doesn't look that different to me:
in particular
In Erlang (and Elixir is similar) something like (again, assuming that the sides are sorted by length so that equal sides will always be adjacent)
or
ReScript (aka ReasonML; JavaScript flavored OCaml)
etc.
very likely.
And nice overview, of how different languages handle the same problem