Hello Everyone!

It’s time for practice coding

Please try below coding problem and reply your answer.

**1. Palindrome Checker: Write a function that takes a string and returns true if the string is a palindrome and false otherwise. A palindrome is a word, phrase, number, or other sequence of characters that reads the same backward as forward.**

**2.Find the Longest Word in a String: Write a function that takes a string and returns the length of the longest word in the string.**

**3.Find the Missing Letter: Write a function that takes a string of consecutive letters and returns the missing letter in the sequence.**

Have a Happy Learning

Thanks & Regards

Teaching Assistant,

Dharshini M.

2 Likes

//1. Palindrome Checker: Write a function that takes a string and returns true if the string is a palindrome and false otherwise. A palindrome is a word, phrase, number, or other sequence of characters that reads the same backward as forward.

function palindromeChecker(myStr){

myArr= myStr.split(‘’).reverse().join(‘’)

if(myArr == myStr){

return true

}

return false

}

let result=palindromeChecker(“noon”)

console.log(result)

//2.Find the Longest Word in a String: Write a function that takes a string and returns the length of the longest word in the string.

let wordLength=0;

function longestWord(myStr){

myArr= myStr.split(’ ')

for(i=0; i<myArr.length;i++){

if(myArr[i].length>wordLength){

wordLength=myArr[i].length

}

}

return wordLength;

}

let longestLength= longestWord(“sanjay is very much excited to learn coding”)

console.log("length of the longest word is : ",longestLength)

2 Likes

Hi Dharshini,

can you please explain about the 3rd question.

@deekondasanjaykumar @abhitiwari.jnv566

Thank you for your Valuable response

Here I attach the Explanation for 3 rd Question.Please answer for this also.

**The “Find the Missing Letter” question is a programming problem that requires you to write a function that takes a string of consecutive letters as input and returns the missing letter in the sequence.**

**For example, if the input string is “abdefg”, the missing letter is “c”, so the function should return “c”. Similarly, if the input string is “lmnop”, the missing letter is “q”, so the function should return “q”.**

**To solve this problem, you need to find the missing letter in the sequence by comparing each letter with its successor. If the difference between two consecutive letters is greater than 1, you have found the missing letter.**

Have a Happy Learning!

// 3.Find the Missing Letter: Write a function that takes a string of consecutive letters and returns the missing letter in the sequence.

function missingLetter(str3) {

let splitString = str3.split(‘’);

for (i = 0; i < splitString.length; i++) {

const current = splitString[i].charCodeAt();

const next = splitString[i+1].charCodeAt();

```
if (next - current !== 1) {
return String.fromCharCode(current + 1);
}
```

}

return null;

}

console.log(missingLetter(“abcdeghi”));

console.log(“Q3 …END”);

//3.Find the Missing Letter: Write a function that takes a string of consecutive letters and returns the missing letter in the sequence.

function missingLetter(s){

let alpha=“abcdefghijklmnopqrstuvwxyz”

let alphaIndex=alpha.indexOf(s[0])

for(i=0;i<alpha.length;i++){

if(s[i] !== alpha[alphaIndex + i]){

return alpha[alphaIndex + i]

}

}

}

console.log(missingLetter(“abdefg”))

@deekondasanjaykumar @abhitiwari.jnv566 Hey! You are so active Keep it up !

Have a Happy Learning!

Thank you for your response!

1 Like