Last active
July 21, 2017 09:51
-
-
Save wstucco/57f0812292bbfe21c6f154b3f2b2c951 to your computer and use it in GitHub Desktop.
most similar ip 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
{:ok, ips} = :inet.getif() | |
ips | |
|> Enum.map(fn {ip, _broadaddr, _mask} -> ip |> Tuple.to_list |> Enum.map_join(".", &to_string/1) end) | |
|> Enum.map(fn ip -> {ip, String.jaro_distance(ip, "192.168.99.100")} end) | |
|> Enum.sort(fn {_, score1}, {_, score2} -> score1 > score2 end) | |
|> List.first | |
|> elem(0) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment