Skip to content

Instantly share code, notes, and snippets.

@thillain
Created April 6, 2020 02:23
Show Gist options
  • Save thillain/90f032cf43b992d1eae4191354196258 to your computer and use it in GitHub Desktop.
Save thillain/90f032cf43b992d1eae4191354196258 to your computer and use it in GitHub Desktop.
Questions Marks
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