Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

JavaScript String Questions

The document contains a series of JavaScript string manipulation questions, each requiring the implementation of specific functions to perform tasks such as counting characters, checking for palindromes, and concatenating strings. Each question includes input and output formats, constraints, and examples for clarity. The tasks range from simple character counting to more complex string operations, providing a comprehensive exercise set for practicing JavaScript string handling.

Uploaded by

Kartik Agrawal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

JavaScript String Questions

The document contains a series of JavaScript string manipulation questions, each requiring the implementation of specific functions to perform tasks such as counting characters, checking for palindromes, and concatenating strings. Each question includes input and output formats, constraints, and examples for clarity. The tasks range from simple character counting to more complex string operations, providing a comprehensive exercise set for practicing JavaScript string handling.

Uploaded by

Kartik Agrawal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

JavaScript String Questions

Q1. Count Characters

You are given a string S, and your task is to return an array B(having a size of 2), where B[0] contains the count of
character A (uppercase) in string S and B[1] contains the count of character D (uppercase) in string S.
Note: You have to complete countCharacters function. No need to take any input.

Input Format

The first and the only line of the input contains a string S.

Output Format

Return array B as output.

Constraints

1≤|S|≤100, where |S| denotes the length of string S. S contains both lowercase and uppercase alphabets.

Example

Sample Input
AbaDd
Sample Output
11

Q2. Count the Heads


Tina is given a string S which contains the first letter of all the student names in her class. She got a curiosity to check how
many people have their names starting from the same alphabet. So given a string S, she decided to write a code that finds
out the count of characters that occur more than once in the string.
Note: You have to complete Count Head function. No need to take any input.

Input Format

The first and the only line of the input contains a string S (with no space and contains only lowercase letters).

Output Format

Return updated String S as output, where the string contains the charcter followed by their occurrence (if greater than 1) in
alphabetical order.

Constraints

1≤|S|≤100, where |S| denotes the length of string S. S contains only lowercase alphabets.

Example
Sample Input
prepbytes
Sample Output
e2p2
Q3. Count the Vowels

You are given a string S containing both uppercase and lowercase letters. You need to find out the number of vowels in the
given string.
Note: You have to complete Count_Vowel function. No need to take any input.

Input Format

The first and only line of the input contains string S.

Output Format

Return the number of Vowels in the string S as output.

Constraints

1≤|S|≤100, where |S| denotes the length of string S.

Example
Sample Input
Prepbytes
Sample Output
2

Q4. Concatenate the Strings

You are given two strings S1 and S2 (containing both uppercase and lowercase letters), You need to retrun a string which is the
concatenation of both the given strings.
Note: You have to complete Concatenate_Strings function. No need to take any input.

Input Format

The first line of the input contains the first string S1 and the second line of input contains the second string S2.

Output Format

Return the String S3 as output, which is the concatenation of given both strings.

Constraints

1≤|S1|,|S2|≤100, where |S|denotes the length of string S.

Example
Sample Input
Prep bytes
Sample Output
Prepbytes

Q5. Find Length

You are given a string S, and your task is to return the length of the string S.
Note: You have to solve it without using length method. You have to complete findLength function. No need to take any input.

Input Format

The first and the only line of the input contains a string S.

Output Format
Return the length of the string S.

Constraints

1≤|S||≤100, where |S| denotes the length of string S. S contains both lowercase and uppercase alphabets.

Example

Sample Input
CeDqe
Sample Output
5

Q6. Find the Winner

You are given a string S consisting of two letters A and D,where each character represent the winner of N games played between Aditya
and Danish, where letter A represents the win of Aditya and letter D represents the win of Danish. You need to find out the that which
player wins the maximum number of games or there is a draw between them.
Note: You have to complete Game_Winner function. No need to take any input.

Input Format

The first and only line of the input contains string S.

Output Format
Return the name of the player who have won the maximum number of games, if both player won same number of games return Draw.

Constraints

1≤|S|≤100, where |S| denotes the length of string S.

Example
Sample Input 1
ADDAAADDDDD
Sample Output 1
Danish
Sample Input 2
ADDAAADD
Sample Output 2
Draw

Q7. Join Strings

You are given two strings S and P, and your task is to concatenate them and return the concatenated string.
Note: You have to complete joinStrings function. No need to take any input.

Input Format

The first and the only line of the input contains two space-separated strings S and P.

Output Format
Return the final concatenated string.

Constraints

1≤|S|,|P|≤100, where |S|and |P| denote the length of string S and P, respectively. S and P contain both lowercase and uppercase
alphabets.
Example
Sample Input
PrepBytes Technologies
Sample Output
PrepBytesTechnologies

Q8. Plaindrome Check

You are given a string S, Your task is to check wether the given string is a Palindrome or not.
A Palindrome is a string, which turnout same when read in reverse direction. Example: "naman" is a Palindrome. String can contain
both upppercase lowercase letters.
Note: You have to complete Plain_Check function. No need to take any input.

Input Format

The first and the only line of the input contains a string S.

Output Format

Return "True" if the given string is Palindrome else return "False" (without " ") .

Constraints

1≤|S|≤100, where |S| denotes the length of string S. S contains both lowercase and uppercase alphabets.

Example

Sample Input 1
Naman
Sample Output 1
False
Sample Input 2
naman
Sample Output 2
True

Q9. Reverse the String

You are given a string S, Your task is to Reverse the string. String can contain both upppercase lowercase letters. Note: You have to
complete Reverse_String function. No need to take any input.

Input Format

The first and the only line of the input contains a string S.

Output Format
Return the reversed String.

Constraints

1≤|S|≤100, where |S| denotes the length of string S. S contains both lowercase and uppercase alphabets.

Example
Sample Input
I am utkarsh raj
Sample Output
jar hsraktu ma I

Q10. Match the Strings

You are given two strings S1 and S2, Your task is to print YES if both strings are same else print NO.
Note: You have to complete String_Match function. No need to take any input.

Input Format

The first line of the input contains a string S1. The second line of the input contains a string S2.

Output Format

Return YES if S1 and S2 are same, else return NO.

Constraints

1≤|S1|,|S2|≤100, where |S| denotes the length of string S. S1 and S2 contains both lowercase and uppercase alphabets.

Example
Sample Input
Prepbytes Prepbytes
Sample Output
YES

Q11. String Replace

You are given a string S, along with a pattern string and a text string. You need to repalce the pattern string in S to the text string.
Note: You have to complete Replace function. No need to take any input.

Input Format

The first and the only line of the input contains a string S.

Output Format

Return updated String S as output.

Constraints

1≤|S|≤100, where |S| denotes the length of string S. S contains both lowercase and uppercase alphabets.

Example

Sample Input
Hi, I am You. You Prepbytes
Sample Output
Hi, I am Prepbytes.

Q12. Split the String

You are given a string S, Your task is to split the string with respect to spaces.
Note: You have to complete Split_the_String function. No need to take any input.

Input Format

The first and the only line of the input contains a string S.
Output Format

Return the array of splitted strings of S.

Constraints

1≤|S|≤100, where |S|denotes the length of string S. S contains both lowercase and uppercase alphabets.

Example

Sample Input
I am utkarsh raj
Sample Output
I
am
utkarsh
raj

Q13. Count the Vowels and Consonants

You are given a string S containing both uppercase and lowercase letters. You need to find out the number of vowels and the number of
consonants in the given string.
Note: You have to complete Count_Vowels function and Count_Consonants function. No need to take any input.

Input Format

The first and only line of the input contains string S.

Output Format

Return the number of Vowels and the number of Consonants in the string S in the functions.

Constraints

1≤|S|≤100, where |S|denotes the length of string S.

Example
Sample Input
Prepbytes
Sample Output
27

You might also like