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:
Complete the countCharacters
function. No need to take any input.
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
.
countCharacters
function. No need to take any input.
const countCharacters = (S) => {
var B = [];
var countA = 0, countD = 0;
for(let i=0; i < S.length; i++){
if(S[i] === "A"){
countA++;
}
else if(S[i] === "D"){
countD++
}
}
B.push(countA);
B.push(countD);
return B;
};
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: Complete the Count_Occ
function. No need to take any input.
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.
Count_Occ
function. No need to take any input.
var Count_Occ = (s) => {
let Arr = s.split("").sort();
var p;
let map1 = new Map();
for(let i =0; i<Arr.length;i++){
p=0;
Arr.reduce((acc,val)=>{
if(val == Arr[i]){
p=acc+1;
}
return p;
}, 0);
map1.set(`${Arr[i]}` , p);
}
let z = [];
map1.forEach((value,key)=>{
if(value>1){
z.push(key + "" + value);
}
});
return (z.join(""));
};
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: Complete the Count_Vowels
function. No need to take any input.
S
containing both uppercase and lowercase letters. You need to find out the number of vowels in the given string.Count_Vowels
function. No need to take any input.var Count_Vowels= (S) =>{
var count = 0;
for(let i=0; i < S.length; i++){
if(S[i]==="A"||S[i]==="a"||S[i]==="E"||S[i]==="e"||S[i]==="I"
||S[i]==="i"||S[i]==="O"||S[i]==="o"||S[i]==="U"||S[i]=="u"){
count++;
}
}
return count;
};
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: Complete the Concatenate_Strings
function. No need to take any input.
S1
and S2
(containing both uppercase and lowercase letters), You need to retrun a string which is the concatenation of both the given strings.Concatenate_Strings
function. No need to take any input.var Concatenate_Strings = (S1, S2) => {
S3 = S1+S2;
return S3;
};
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. Complete the findLength
function. No need to take any input.
S
, and your task is to return the length of the string S
.findLength
function. No need to take any input.const findLength = (S) => {
var count = 0;
for(i=0; i < S.length; i++){
count++;
}
return count;
};
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: Also, in the output array, the age should be in the same order as in the input array. Complete the Game_Winner
function. No need to take any input.
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.
Game_Winner
function. No need to take any input.var Game_Winner = (S) => {
var Aditya = 0;
var Danish = 0;
for(let i=0; i < S.length; i++){
if(S[i]==="A"){
Aditya++;
}
else Danish++;
}
if(Aditya!==Danish){
if(Aditya < Danish){
return "Danish";
}
else return "Aditya";
}
else return "Draw";
};
Join Strings.
You are given two strings S
and P
, and your task is to concatenate them and return the concatenated string.
Note: Complete the joinStrings
function. No need to take any input.
S
and P
, and your task is to concatenate them and return the concatenated string.joinStrings
function. No need to take any input.const joinStrings = (S, P) => {
let str=''
str=S+P
return str
};
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: Complete the Palin_Check
function. No need to take any input.
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.
Palin_Check
function. No need to take any input.var Palin_Check = (str) => {
var i = 0;
j = str.length - 1;
while (i < j) {
if (str.charAt(i) !== str.charAt(j)){
return "False";
}
i++;
j--;
}
return "True";
};
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.
S
, Your task is to Reverse the string. String can contain both upppercase lowercase letters.Reverse_String
function. No need to take any input.var Reverse_String = (str) => {
arr = [];
reverseStr = "";
for(let i=str.length-1; i>=0; i--){
reverseStr += str[i]
}
return reverseStr;
};
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: Complete the String_Match
function. No need to take any input.
S1
and S2
, Your task is to print YES if both strings are same else print NO.String_Match
function. No need to take any input.var String_Match = (S1,S2) => {
if(S1==S2){
return 'YES';
}
else{
return 'NO';
}
};
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: Complete the Replace
function. No need to take any input.
S
, along with a pattern string and a text string. You need to repalce the pattern string in S
to the text string.Replace
function. No need to take any input.var Replace = (S, pattern , text) => {
return S.replace(pattern,text)
};
Split the String.
You are given a string S
, Your task is to split the string with respect to spaces.
Note: Complete the Split_the_string
function. No need to take any input.
S
, Your task is to split the string with respect to spaces.Split_the_string
function. No need to take any input.var Split_the_string = (S) => {
word = ""
arr = []
for(let i=0;i < S.length;i++){
if(S[i]!==" "){
word += S[i]
}
else{
arr.push(word);
word = ""
}
}
arr.push(word)
return arr
};
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: Complete the Split_the_string
function. No need to take any input.
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.Split_the_string
function. No need to take any input.var Count_Vowels= (S) => {
S=S.toUpperCase();
let countV=0;
for(i=0;i < S.length;i++){
if(S[i]=='A' || S[i]=='E' || S[i]=='O' || S[i]=='I' || S[i]=='U'){
countV+=1;
}
}
return countV;
};
var Count_Consonants= (S) => {
S=S.toUpperCase();
let countV=0;
let countC=0;
for(i=0;i < S.length;i++){
if(S[i]=='A' || S[i]=='E' || S[i]=='O' || S[i]=='I' || S[i]=='U'){
countV+=1;
}
else{
countC+=1;
}
}
return countC;
};