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.119 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.118 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.117 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.116 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.115 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.114 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.113 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.111 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.110 tracks/elixir/exercises/series/example.exs