Skip to content

Instantly share code, notes, and snippets.

@wusisu
Created December 5, 2016 09:05
Show Gist options
  • Save wusisu/c89e4a4a0a3e44b5bc49386eec386679 to your computer and use it in GitHub Desktop.
Save wusisu/c89e4a4a0a3e44b5bc49386eec386679 to your computer and use it in GitHub Desktop.
const Minganci = ['+1s', '轮子哥']
const String = 'ajsldkfja+1sjsdjwoi轮子哥jsodifj'
const ALL = {}
const putInWord = (word, box)=> {
if (!word) return
if (word.length === 1) return box[word] = true
const c = word[0]
if (box[c] === true) return
if (!box[c]) box[c] = {}
putInWord(word.substr(1), box[c])
}
Minganci.forEach(w=>putInWord(w, ALL))
const startWithOneCharacter = (s, checker) => {
let index = 0;
for (var i = 0; i < s.length; i++) {
checker = checker[s[i]]
if (checker === true) return true
if (!checker) return
}
}
const checkViolations = (raw, checker) => {
const mgc = []
const length = raw.length
for (var i = 0; i < length; i++) {
if (startWithOneCharacter(raw, checker)) mgc.push(i)
raw = raw.substr(1)
}
return mgc;
}
console.log(ALL)
console.log(checkViolations(String, ALL))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment