Untitled
unknown
typescript
a month ago
893 B
2
Indexable
Never
function theTest(text: string): string { const charaterToReplace = 'a'; let result = text //To check if text is palindrome for (let i = 0; i < text.length; i++) { const j = text.length - i - 1 if (i >= j) { break } if (text[i] == '?' && text[j] == '?') { // result = charaterToReplace; result = replaceAtIndex(result, i, charaterToReplace) result = replaceAtIndex(result, j, charaterToReplace) continue } if (text[i] == '?') { result = replaceAtIndex(result, i, text[j]) continue; } if (text[j] == '?') { result = replaceAtIndex(result, j, text[i]) continue; } if (text[i] != text[j]) { return "NO" } } return result } function replaceAtIndex(text: string, index: number, replacement: string): string { return text.substring(0, index) + replacement + text.substring(index + replacement.length); } console.log(theTest("?a?"));