Created
April 6, 2020 02:23
-
-
Save thillain/90f032cf43b992d1eae4191354196258 to your computer and use it in GitHub Desktop.
Questions Marks
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
function QuestionsMarks(str) { | |
let numbers = []; | |
let inputStrArr = str; | |
let numbersWithIndex = []; | |
let result = false; | |
for (let i = 0; i < inputStrArr.length; i++) { | |
if (parseInt(inputStrArr[i], 10)) { | |
numbers.push(inputStrArr[i]); | |
numbersWithIndex.push({ | |
number: parseInt(inputStrArr[i], 10), | |
index: i, | |
}); | |
} | |
} | |
for (let j = 0; j < numbersWithIndex.length - 1; j++) { | |
if ( | |
parseInt(numbersWithIndex[j].number, 10) + | |
parseInt(numbersWithIndex[j + 1].number, 10) === | |
10 | |
) { | |
result = true; | |
let subStr = inputStrArr.substring( | |
numbersWithIndex[j].index + 1, | |
numbersWithIndex[j + 1].index | |
); | |
subStr = subStr.replace(/[a-zA-Z]/g, ''); | |
if (!subStr.includes('???')) { | |
result = false; | |
return false; | |
} | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment