Skip to content

Instantly share code, notes, and snippets.

@GavinRay97
Created April 29, 2018 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GavinRay97/2c138b0b4c623c9adfb48c6116f6ef06 to your computer and use it in GitHub Desktop.
Save GavinRay97/2c138b0b4c623c9adfb48c6116f6ef06 to your computer and use it in GitHub Desktop.
Find all unique substrings of a string
const findUniqueSubstrings = (str) => {
const arr = [...str].reduce((acc, _, idx) =>
acc.concat(Array.from({length: str.length}, (_, innerIdx) =>
str.substring(idx, innerIdx + 1)
)), [])
return new Set(arr)
}
findUniqueSubstrings("Your string here")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment