String Q27
String Q27
1. Problem: Write a program to remove all vowels (a, e, i, o, u) from a given string.
Input:
"JavaScript is fun";
Output:
"JvScrpt s fn";
Solution:
function removeVowels(str) {
return str.replace(/[aeiouAEIOU]/g, ""); // Remove vowels using regex
}
// Test cases
console.log(removeVowels("JavaScript is fun")); // Output: "JvScrpt s fn"
console.log(removeVowels("Hello World")); // Output: "Hll Wrld"
console.log(removeVowels("I love programming")); // Output: " lv prgrmmng"
console.log(removeVowels("AEIOU are vowels")); // Output: " r vwls"
Explanation:
2. Problem: You are given a sentence as a string. Write a program to find the longest
word in the sentence.
Input:
Output:
"JavaScript";
Solution:
function findLongestWord(sentence) {
let words = sentence.split(" ");
let longest = "";
return longest;
}
// Test cases
console.log(findLongestWord("JavaScript makes coding enjoyable")); // Output: "JavaScript"
console.log(findLongestWord("I love programming")); // Output: "programming"
console.log(findLongestWord("The quick brown fox jumps over the lazy dog")); // Output:
"jumps"
console.log(findLongestWord("Hello world!")); // Output: "Hello"
Explanation:
3. Problem: Write a program to capitalize the first letter of each word in a given
sentence.
Input:
"javascript is powerful";
Output:
"Javascript Is Powerful";
Solution:
function capitalizeWords(sentence) {
return sentence
.split(" ") // Split the sentence into words
.map((word) => word.charAt(0).toUpperCase() + word.slice(1)) // Capitalize first letter
.join(" "); // Join words back into a sentence
}
// Test cases
console.log(capitalizeWords("javascript is powerful")); // Output: "Javascript Is Powerful"
console.log(capitalizeWords("hello world")); // Output: "Hello World"
console.log(capitalizeWords("i love coding")); // Output: "I Love Coding"
console.log(capitalizeWords("a quick brown fox")); // Output: "A Quick Brown Fox"
Explanation:
4. Problem: You are given a string with words separated by spaces. Write a program to
reverse the letters in each word while keeping the word order the same.
Examples:
Input:
"tpircSavaJ si emosewa"
Solution:
function reverseLettersInWords(sentence) {
return sentence
.split(" ") // Split sentence into words
.map((word) => word.split("").reverse().join("")) // Reverse each word
.join(" "); // Join words back into a sentence
}
// Test cases
console.log(reverseLettersInWords("JavaScript is awesome")); // Output: "tpircSavaJ si
emosewa"
console.log(reverseLettersInWords("I love coding")); // Output: "I evol gnidoc"
console.log(reverseLettersInWords("Hello World")); // Output: "olleH dlroW"
console.log(reverseLettersInWords("SingleWord")); // Output: "droWelgniS"
Explanation:
1. Frontend Technologies
Learn ReactJS, Angular, and modern UI/UX design.
2. Full Stack Development
Master MERN stack, Java, Python, or .NET technologies.
3. Data Science and Analytics
Gain skills in data visualization, modeling, and analysis.
4. Artificial Intelligence and Machine Learning
Explore AI tools, concepts, and practical implementations.
5. Advanced Topics
o Cloud Computing: AWS, Azure
o Cybersecurity: Ethical hacking, penetration testing
How to Enroll?