Skip to content

Instantly share code, notes, and snippets.

@AndrewThian
Created February 9, 2019 05:25
Show Gist options
  • Save AndrewThian/e59297979fa97ca2ae1782d5c2ffec1f to your computer and use it in GitHub Desktop.
Save AndrewThian/e59297979fa97ca2ae1782d5c2ffec1f to your computer and use it in GitHub Desktop.
asserts if string contains another string
function checkstring(str) {
let pointer = 0;
let len = str.length
let smileCount = 0
let smileyBank = []
while (pointer < len - 1) {
const currentSymbol = str[pointer]
const nextSymbol = str[pointer + 1]
if (currentSymbol === ":") {
console.log(currentSymbol, nextSymbol)
if (nextSymbol === ")") {
smileCount++
pointer = pointer + 1
smileyBank.push(currentSymbol + nextSymbol)
}
} else if (currentSymbol === "(") {
console.log(currentSymbol, nextSymbol)
if (nextSymbol === ":") {
smileCount++
pointer = pointer + 1
smileyBank.push(currentSymbol + nextSymbol)
}
}
pointer++
}
console.log(smileCount)
console.log(smileyBank)
}
function containsString(string1, string2) {
let charArray1 = string1.split('');
let charArray2 = string2.split('');
let leftPointer = 0;
let rightPointer = charArray2.length - 1
let matchCounter = 0;
while(rightPointer < charArray1.length) {
for (let i = leftPointer; i < rightPointer + 1; i++) {
const arr2Counter = i - leftPointer
if (charArray1[i] === charArray2[arr2Counter]) {
matchCounter++
}
if (charArray2.length === matchCounter) {
return true
}
}
leftPointer++
rightPointer++
}
return false
}
// console.log(containsString("applegate", "gate"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment