Sha256: 20f28907a4492268bdfc507fae19dc57d97ccbef3b4f2072848a773df2c3a911

Contents?: true

Size: 445 Bytes

Versions: 69

Compression:

Stored size: 445 Bytes

Contents

defmodule StringSeries do
  @doc """
  Given a string `s` and a positive integer `size`, return all substrings
  of that size. If `size` is greater than the length of `s`, or less than 1,
  return an empty list.
  """
  @spec slices(s :: String.t(), size :: integer) :: list(String.t())
  def slices(_s, size) when size < 1, do: []

  def slices(s, size) do
    s |> String.graphemes() |> Enum.chunk(size, 1) |> Enum.map(&Enum.join/1)
  end
end

Version data entries

69 entries across 69 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.179 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.178 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.177 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.176 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.175 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.174 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.173 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.172 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.171 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.170 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.169 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.167 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.166 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.165 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.164 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.163 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.162 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.161 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.160 tracks/elixir/exercises/series/example.exs