acrolink
How to check if a variable is an Integer Array or a String of comma separated integer values?
How to determine that:
[11,15] is an Integer Array? [true or false] ?
and that:
"[11,15]" is a string having this structure ?
Thank you.
Most Liked
soup
What have you tried so far? What do you think the steps might be, if you break both problems down? Can you use a solution to the first problem to solve the second?
LostKobrakai
The second question cannot be answered without knowing by which criteria you consider "[11,15]" to be an array of integers. Like is it meant to be json formatted, elixir code, anything else?
kodepett
Considering double quotes as part of the string, below might work
`
def test(data) when is_binary(data), do: true
def test(data) when is_list(data) do
data
|> Enum.all?(&is_integer/1)
end
`
For the string, you can return a tuple indicating the type. Sorry; typing from a phone.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









