Created
April 29, 2018 06:39
-
-
Save GavinRay97/2c138b0b4c623c9adfb48c6116f6ef06 to your computer and use it in GitHub Desktop.
Find all unique substrings of a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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