series
This commit is contained in:
12
elixir/series/lib/string_series.ex
Normal file
12
elixir/series/lib/string_series.ex
Normal file
@@ -0,0 +1,12 @@
|
||||
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) do
|
||||
length = String.length(s)
|
||||
for start <- 0..(length - size), size in 1..length, into: [], do: String.slice(s, start, size)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user