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.159 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.158 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.157 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.156 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.155 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.154 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.153 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.152 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.151 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.150 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.149 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.148 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.147 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.146 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.145 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.144 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.143 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.142 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.141 tracks/elixir/exercises/series/example.exs
trackler-2.2.1.140 tracks/elixir/exercises/series/example.exs