Last active
September 22, 2022 02:26
-
-
Save uxjp/b2b04c52790a2f10301f36695724cff9 to your computer and use it in GitHub Desktop.
Filter list Elixir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Solution do | |
[max | tail ] = IO.read(:all) | |
|> String.split | |
|> Enum.map(&String.to_integer/1) #everything is already integer after this | |
tail | |
|> Enum.filter(fn x -> x < max end) | |
|> Enum.each(&IO.puts/1) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Solution do | |
[max | tail ] = IO.read(:all) | |
|> String.split | |
|> Enum.map(&String.to_integer/1) | |
tail | |
|> Enum.filter(&(&1 < max)) | |
|> Enum.each(&IO.puts/1) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Solution do | |
#I'm not familiar with this yet [1/2] | |
def filter_by_max([max | nums]) do | |
Enum.filter(nums, &(&1 < max)) | |
end | |
def main() do | |
IO.read(:stdio, :all) | |
|> String.split() | |
|> Enum.map(&String.to_integer(&1)) | |
# the way this function is called [2/2] | |
|> filter_by_max() | |
|> Enum.each(&(IO.puts(&1))) | |
end | |
end | |
Solution.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.hackerrank.com/challenges/fp-filter-array/problem?isFullScreen=true