Skip to content

Instantly share code, notes, and snippets.

@Announcement
Last active May 10, 2018 00:13
Show Gist options
  • Save Announcement/da000a78fea955b2446775b5aff9050f to your computer and use it in GitHub Desktop.
Save Announcement/da000a78fea955b2446775b5aff9050f to your computer and use it in GitHub Desktop.
optimizations needed
function getSubstrings (string) {
var map = new Map
for (let n = 1; n < string.length; n++) {
for (let i = 0; i < string.length - n; i++) {
const item = string.substring(i, i + n)
if (!map.has(item))
map.set(item, new Set)
map.get(item).add(i)
}
}
return map
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment