String ends with?

Elixir

defmodule EndsWith do
  def solution(str, ending) when ending == "", do: true

  def solution(str, ending) do
    string_len = String.length(str)
    search_len = String.length(ending)
    ending == String.slice(str, -search_len, string_len)
  end

end

Tags

  1. elixir (Private)
  2. 7-kyu (Private)
  3. codewars (Private)
  4. answer (Private)