Highest Scoring Word
Elixir
defmodule Kata do
def high(str) do
words = String.split(str, " ")
word_values = Enum.map(words, fn word -> get_word_value(word) end)
max_value = Enum.max(word_values)
index = Enum.find_index(word_values, fn x -> x == max_value end)
Enum.at(words, index)
end
def get_word_value(word) do
chars = String.split(word, "", trim: true)
Enum.reduce chars, 0, fn (char, acc) ->
<<val::utf8>> = char
val - 96 + acc
end
end
end
- elixir (Private)
- 6-kyu (Private)
- codewars (Private)
- answer (Private)