Question

In: Computer Science

Write a function in JAVASCRIPT that accepts two arguments (a string array and a character). The...

Write a function in JAVASCRIPT that accepts two arguments (a string array and a character). The function will check each character of the strings in the array and removes the character, regardless of case. If the first letter of the string is removed the next letter must be capitalized. Your function would return the result as one string, where each element of array is separated by comma. E.G. function([“John”,”Hannah”,”Saham”], “h”); // returns ‘Jon,Anna,Saam

Use of any built in string function or any built in array function is not alllowed,

any help would be much appreciated.

Solutions

Expert Solution

//function to remove given character from array of strings

//input: Array of strings, character to remove

//output: String as specified per requirements

function removeChar(StringArray,Ch){

var n2,result;

var n1 = Ch.charCodeAt(0);

if(n1 >= 97) n2 = n1 - 32;

else n2 = n1 + 32;

var length = 0;

var stringLength,temp;

var finalResult = "";

//first find the length of array of strings

while (StringArray[length] !== undefined)

length++;

//Iterate through each string from array

for(var i = 0; i< length;i++){

//first find length of each string

stringLength = 0;

result = "";

//each string is assigned to temp

temp = StringArray[i];

//stringLength has length of the string

while (temp[stringLength] !== undefined) stringLength++;

for(var j = 0;j<stringLength;j++)

{

if(temp.charCodeAt(j) != n1 && temp.charCodeAt(j) != n2 )

{

if(result == '' && temp.charCodeAt(j) >= 97) result +=String.fromCharCode(temp.charCodeAt(j) - 32);

else result = result + temp[j];

}

}

if(i != length - 1) finalResult = finalResult + result + ',';

else finalResult = finalResult + result;

}

return finalResult;

}

console.log(removeChar(["John","Hannah","Saham"],"h"))

//output:


**************************************************************************
Please give an upvote,as it matters to me a lot :)
Got any doubts? Feel free to shoot them in the comment section
**************************************************************************


Related Solutions

Write a Python function that accepts three arguments: an array, the size of the array, and...
Write a Python function that accepts three arguments: an array, the size of the array, and a number n. Assume that array contains integers. The function should display all integers in the array that are greater than the number n. Test your function.
Write a function in JAVASCRIPT that accepts an array as argument. The function should loop through...
Write a function in JAVASCRIPT that accepts an array as argument. The function should loop through the array elements and accumulate the sum of ASCII value of each character in element and return the total. For example: function([‘A’, ‘bc’, 12]); // returns 361 which is the sum of 65 + 98 + 99 + 49 + 50 Use of any built in string functions or built in array functions is not allowed, Any help would be much appreciated
Write a function that accepts an int array and the array's size as arguments.
Write a function that accepts an int array and the array's size as arguments. The function should create a copy of the array, except that the element values should be reversed int the copy. The function should return a pointer to the new array. Demonstrate the function in a complete program.  
In c++ Write a function that: accepts a string and an integer as it's only arguments...
In c++ Write a function that: accepts a string and an integer as it's only arguments uses the argument to open a file for writing writes the integer to the file if it fails to open the file, returns -1 if it succeeds in opening the file, returns 0 does not interact with the user in any way does not use global variables
C++ Write a function that accepts an array of doubles and the array's size as arguments....
C++ Write a function that accepts an array of doubles and the array's size as arguments. The function should display the contents of the array to the screen.
Using Python #Write a function called after_second that accepts two #arguments: a target string to search,...
Using Python #Write a function called after_second that accepts two #arguments: a target string to search, and string to search #for. The function should return everything in the first #string *after* the *second* occurrence of the search term. #You can assume there will always be at least two #occurrences of the search term in the first string. # #For example: # after_second("11223344554321", "3") -> 44554321 # #The search term "3" appears at indices 4 and 5. So, this #returns everything...
In this third part, write a function that accepts an array of integers and its size as arguments.
in C++In this third part, write a function that accepts an array of integers and its size as arguments. The function should create a new array that is of half size the argument array (round up the fraction if the size of the argument array is odd). The value of the first element (Element 0) of the new array should be the sum of the first two elements of the argument array (Element 0 and 1). Element 1 of the...
Element Shifter: Write a function that accepts an int array and the array’s size as arguments....
Element Shifter: Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to element 1 of the new array, element 1 of the argument array should be copied to element 2 of the new array, and so forth. The...
Javascript 1. Write a function which receives four arguments (array, start, end, delimiter). Copy the array...
Javascript 1. Write a function which receives four arguments (array, start, end, delimiter). Copy the array values from the start to end index separated by delimiter\'s value. function([1,2,3,4],1,3,'*') // returns 2*3*4 as string 2. Write a function to change the case of all the characters in string based on their position which matches the value of the pos parameter passed to function(str, pos [even|odd]). Example: function(‘abCd’, ‘odd’) // returns Abcd 3 Write a function which receives two arguments (array, oddOrEven)...
Write a program that accepts a string and character as input, then counts and displays the...
Write a program that accepts a string and character as input, then counts and displays the number of times that character appears (in upper- or lowercase) in the string. Use C++ Enter a string: mallet Enter a character: a "A" appears 1 time(s) Enter a string: Racecar Enter a character: R "R" appears 2 time(s)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT