QuestionQuestion

Description
In this assignment, you are going to create a JavaScript file containing 10 functions. Each function represents one step and 10 marks are assigned to each step (function). The functions you are creating might be very similar to a built-in function found predefined in the JavaScript language.
Each function needs to be considered as an individual problem. Focus on each function one problem at a time until all 10 functions are defined.
There are two versions of the assignment. The last two digits of your student id determine the set of steps you must implement. Check the what to implement section of this document for more details.
What to implement?
• Create only one JavaScript file which must be called STUDENT_ID-functions.js.
• All the functions you implement must be placed in STUDENT_ID-functions.js and you are not allowed to use any external file or library. Using an extra file or library will produce a zero mark for your assignment.
• Based on the last two digits of your student id, you are required to implement the following functions
• Student ID last two digits: 00 to 50
1. Write a function which returns the sum of the values for each parameter it receives. You’ll need to use the JavaScript arguments object to determine the number of parameters.
2. Write a function which returns the calling string value converted to lowercase. //function("ALPHABET"); // return "alphabet"
3. Write a function that returns a subset of a string between one index and another. function(str, indexStart, indexEnd) Example
((‘abcd’,1,10) return ‘bcd’) Example 2 (‘abcd’,0 ,1) return ‘ab’) (similar built-in function substring or substr).
4. Write a function that returns a new string containing all matches. Each match is then replaced by replacement characters. function(str, charToChange, charToReplace)
Example ((‘abc’,’a’,’X’) return Xbc
5. Write a function that returns an index of the receiving string for the first occurrence of the specified character. Start the search with the fromIndex parameter. Returns -1 if the value is not found. function(str,searchChar,fromIndex) (similar built-in function indexof)
6. Write a function which removes whitespace from both ends of the receiving string. Whitespace in this context is all whitespace characters (spaces, tabs, and newlines.) function(" value\t ") //return "value"
7. Write a function which splits the receiving string parameter into an array of strings by separating the string into substrings and return the array. function (stringToSplit, separator) Example (‘a|b|c’, ‘|’ return [‘a’,’b’,’c’], (bcAbd, ‘A’, return [‘bc’, ‘bd’], (bacd, ‘X’ return [‘b’,’a’,’c’,’d’]) (similar built-in function split)
8. The trimRight() method removes whitespace from the right end of a string. Whitespace in this context is all the whitespace characters (spaces, tabs, and newlines.) function(" value\t ") //return " value"
9. Write a function to return a unique concatenated array from 2 arrays.
//function([1,2],[2,4]) //return [1,2,4]’, (Note: similar functionality as Array.concat )
10. Write a function that accepts an array and a value to find and return the first element that is bigger than the given value.
//function([5,15,4],6) //return 15’, (Note: similar functionality as
Array.find )
• Student ID last two digits: 51 to 99
1. Write a function that returns a string containing random characters where the length must be equal to the value of the parameter. // function(5) // return “lduem”; // 5 is the argument passed and 5 is the length of the random character string which is returned
2. Write a function which returns the calling string value converted to upper case. // function("alphabet "); // return "ALPHABET"
3. Write a function which adds the equal amount (numSpace) of whitespace (numSpace) to both ends of the receiving string. // function(str, numSpace) // fn(“hello”, 2); // returns “ hello ”
4. Write a function to change the case of all the characters in the string (str) parameter to its opposite case (upper / lower) when the character position matches the value of the pos parameter. function(str, pos [even|odd]). Example function(‘abCd’, ‘odd’) return Abcd) => a is 1st, b is 2nd, c is 3rd and d is 4th
5. Write a function to return the reversed version of the string it receives as an argument. function(str) example function("abc") return "cba" (similar built-in function reverse).
6. Write a function which combines two strings which are passed as parameters. Mix one character from each string and return the concatenated result. function('ABC','Defg') return ADBeCfg
7. The trimLeft() method removes whitespace from the left end of a string. Whitespace in this context is all the whitespace characters (spaces, tabs, and newlines.) function("\t value ") //return "value "
8. Write a function which removes whitespace from both ends of the receiving string. Whitespace in this context is all the whitespace characters (spaces, tabs, and newlines.) function(" value\t ") //return "value"
9. Write a function to concatenate 2 arrays and return a new array.
//function([1,2],[3,4]) //return [1,2,3,4]’, (Note: same functionality as
Array.concat )
10. Write a function that accepts an array and a value. Check every element of the given array against a given value. Return true if the array elements are bigger than the provided value. // function( [5,10],
5) // false // function([6,10],5) // true’, (Note: similar functionality as
Array.every ).

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

/*
1. Write a function that returns a string containing random characters
where the length must be equal to the value of the parameter.
// function(5) // return “lduem”; // 5 is the argument passed and 5 is
the length of the random character string which is returned
*/
function makeRandomString(length) {
var result = "";
var letters = "abcdefghijklmnopqrstuvwxyz";

for (var i = 0; i < length; i++) {
    result += letters.charAt(Math.floor(Math.random() * letters.length));
}

return result;
}

/*
2. Write a function which returns the calling string value converted to
upper case. // function("alphabet "); // return "ALPHABET"
*/
function capitalizeString(string) {
var result = "";

for (var i = 0; i < string.length; i++) {
    var charCode = string.charCodeAt(i);
    if (charCode >= 97 && charCode <= 122) {
       result += String.fromCharCode(charCode - 32);
    } else {
      result += string.charAt(i);
    }
}

return result;
}

/*
3. Write a function which adds the equal amount (numSpace) of whitespace
(numSpace) to both ends of the receiving string. // function(str, numSpace)
// fn(“hello”, 2); // returns “ hello ”
*/
function addWhitespaceString(string, n) {
var result...

By purchasing this solution you'll be able to access the following files:
Solution.PNG and Solution.js.

50% discount

Hours
Minutes
Seconds
$45.00 $22.50
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats