Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to reverse the string.
DSA Typescript
const reversed = str[1]('').reverse().join('');
Attempts:
3 left
💡 Hint
Common Mistakes
Using toUpperCase() instead of split()
Trying to reverse the string without converting to array
✗ Incorrect
We use split('') to convert the string into an array of characters so that reverse() can be applied.
2fill in blank
mediumComplete the code to check if the string is equal to its reverse.
DSA Typescript
return str === [1];
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with str.length instead of reversed string
Using str.toLowerCase() without reversing
✗ Incorrect
We compare the original string with the reversed string to check for palindrome.
3fill in blank
hardFix the error in the function to ignore case when checking palindrome.
DSA Typescript
const normalized = str[1]();Attempts:
3 left
💡 Hint
Common Mistakes
Using toUpperCase() which also works but is not the chosen answer here
Using trim() which only removes spaces
✗ Incorrect
toLowerCase() converts all letters to lowercase so case differences don't affect palindrome check.
4fill in blank
hardFill both blanks to remove spaces and check palindrome ignoring spaces.
DSA Typescript
const normalized = str[1](/\s+/g, '').toLowerCase(); const reversed = normalized[2]('').reverse().join('');
Attempts:
3 left
💡 Hint
Common Mistakes
Using trim() which only removes spaces at start/end
Using concat which does not remove spaces
✗ Incorrect
We use replace to remove all spaces and split to convert string to array for reversing.
5fill in blank
hardFill all three blanks to create a function that returns true if input is palindrome ignoring case and spaces.
DSA Typescript
function isPalindrome(str: string): boolean {
const normalized = str[1](/\s+/g, '').[2]();
const reversed = normalized[3]('').reverse().join('');
return normalized === reversed;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using trim instead of replace to remove all spaces
Not converting to lowercase before checking
Not splitting string before reversing
✗ Incorrect
We remove spaces with replace, convert to lowercase with toLowerCase, and split to array before reversing.
