I agree that we should always try to leverage TypeScript's types. For instance, this function's signature could be more strict with its typing. But those types go away at runtime.
I believe we should still, at the very least, protect against predictable type errors such as calling "filter" on a string. Because a consumer may still send a string.
My perspective is coming from API development. But if we're talking about an arrangement of code and modules where the developer has complete control over inputs, I'd agree more with leaning into typing over runtime checks.
Unfortunately I don't think this is good advice. It's technically correct, yes, but being able to constrain the type of some variable is the entire point of TypeScript. Our first suggestion here should be to use that capability, not to improve our runtime type checks.
I cant belive you guys code it more cleaner than mine haha
Because comments under solutions are visible on the home page dashboard. xD
Why should he flag spoilers if you're already in the literal solutions section.. xD
Smart! :) Should've thought of that..
I agree that we should always try to leverage TypeScript's types. For instance, this function's signature could be more strict with its typing. But those types go away at runtime.
I believe we should still, at the very least, protect against predictable type errors such as calling "filter" on a string. Because a consumer may still send a string.
My perspective is coming from API development. But if we're talking about an arrangement of code and modules where the developer has complete control over inputs, I'd agree more with leaning into typing over runtime checks.
Unfortunately I don't think this is good advice. It's technically correct, yes, but being able to constrain the type of some variable is the entire point of TypeScript. Our first suggestion here should be to use that capability, not to improve our runtime type checks.
Array.isArray() would be a safer check for an Array here, since Strings also have "length" as a property.
use the spoiler flag when posting code (I just added the flag for you)
This comment is hidden because it contains spoiler information about the solution
if it works, it works ^_^
this is how i did mine i forgot the comma between the } and the ( and thought the codewars gods let me down but it turns out im just retarted XD
I'm confused how you weren't required to declare the maps function