Question

(Javascript) Write a function that accepts an array. The function adds its value with the value...

(Javascript) Write a function that accepts an array. The function adds its value with the value of the character before to it to generate a number. It returns a string of numbers.

Homework Answers

Answer #1
function subtracts(lst){
    result = "";
    var k1, k2;
    for(var i = 0;i<lst.length-1;i++){
        if(typeof lst[i] == "string"){
            k1 = lst[i].charCodeAt();
        }
        else{
            k1 = lst[i];
        }
        if(typeof lst[i+1] == "string"){
            k2 = lst[i+1].charCodeAt();
        }
        else{
            k2 = lst[i+1];
        }
        ch = String.fromCharCode(Math.abs(k1+k2));
        if(i == 0){

            result = result + ch;
        }
        else{
            result = result + ","+ ch;
        }
    }
    return result;
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
javascript 1.Write a function delay that accepts two arguments, a callback and the wait time in...
javascript 1.Write a function delay that accepts two arguments, a callback and the wait time in milliseconds. Delay should return a function that, when invoked waits for the specified amount of time before executing. HINT - research setTimeout(); 2.Create a function saveOutput that accepts a function (that will accept one argument), and a string (that will act as a password). saveOutput will then return a function that behaves exactly like the passed-in function, except for when the password string is...
Q5. Code a function, named CountNumerics, that accepts a parameter of a string , named str1,...
Q5. Code a function, named CountNumerics, that accepts a parameter of a string , named str1, and returns the number of numeric characters (‘0’ .. ‘9’) + in the string. Helpful clues:   The string class has a function called length() that can be accessed by str1.length().   To access an individual character in the string; use string indexing (str1[i]) where I is an integer. Indexing of a string array starts at 0.
Write a program that accepts an input string from the user and converts it into an...
Write a program that accepts an input string from the user and converts it into an array of words using an array of pointers. Each pointer in the array should point to the location of the first letter of each word. Implement this conversion in a function str_to_word which returns an integer reflecting the number of words in the original string. To help isolate each word in the sentence, convert the spaces to NULL characters. You can assume the input...
Write a function that accepts an int array and the array’s size as arguments. The function...
Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is twice the size of the argument array. The function should copy the contents of the argument array to the new array, and initialize the unused elements of the second array with 0. The function should return a pointer to the new array. Demonstrate the function by using it in a main program that reads an integer N...
Write a function that accepts an int array and the array’s size as arguments. The function...
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 in the copy. The function should return a pointer to the new array. Demonstrate the function by using it in a main program that reads an integer N (that is not more than 50) from standard input and then reads N integers from a file named data into an...
Write a flatten function in JavaScript that uses recursion to create an array containing all nested...
Write a flatten function in JavaScript that uses recursion to create an array containing all nested arrays in a single array. The function should pass the test: it("longer list, no mutation, completely flat", function () { var data = [[[1],2,[3]],4,[5,6]]; var orig_data = data; expect(ms.flatten(data)).toEqual([1,2,3,4,5,6]); expect(data).toEqual(orig_data); });
Here's my JavaScript question: What is the best way to write a comparator function in JavaScript...
Here's my JavaScript question: What is the best way to write a comparator function in JavaScript that takes 2 strings s1 and s2 and returns true if s1 is alphabetically before s2, and false otherwise? You cannot use the built in sort function, you must create your own sort function. Input strings s1 and s2 are not case sensitive and might not be equal length. Here's two examples: compare('aaa', 'aab') returns true, and compare('aaa', 'aaab') returns true..
Write a function that returns the largest element of an array? Your function should accept a...
Write a function that returns the largest element of an array? Your function should accept a 1-D array as an input and return the largest number. You may assume all numbers are integers. CODE IN C++ PLEASE
C programming Write a function that takes in a 2D char array (string array) and return...
C programming Write a function that takes in a 2D char array (string array) and return a 1D char array with all the elements connected together Hint: strlen(-char*-) //returns the length of a string strcat(-char* accum-, something to add) //works like string+= in java
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an...
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an array of ints, an int value named element, and an int value named end. Return a bool based on whether the element appears in the array starting from index 0 and up to but not including the end index. Generate Random Array Write a function that takes as parameters an array of integers and another integer for the size of the array. Create a...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT