Question

Write a Javascript function that accepts a string. The function takes the last digit of the...

Write a Javascript function that accepts a string. The function takes the last digit of the ASCII

code and returns a string of digits sorted in ascending order. (without using push, sort or other inbuilt function)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

function myfunc(str){
res = ""; ans = '';
for(var i = 0 ; i < str.length ; ++i){

var k = parseInt((str.charCodeAt(i)) % 10);

ans = "";

var j = 0;


for(j = 0 ; j < res.length && (parseInt(res[j])) < k ; ++j){

ans = ans + res[j];

}

ans = ans + k + "";

for(; j < res.length; ++j){

ans = ans + res[j];

}

res = ans;

}
return ans;
}
console.log(myfunc("ONdeq"))


====================================================
SEE OUTPUT

for(j = 0; j < res.length && (parseInt(res[j])) <k; ++i) { 01389 ans = ans + res[j]; ans = ans + k + ; for(; j < res.length

Add a comment
Know the answer?
Add Answer to:
Write a Javascript function that accepts a string. The function takes the last digit of the...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a function in Java Script that accepts a string. The function takes the last digit...

    Write a function in Java Script that accepts a string. The function takes the last digit of the ASCII code and returns a string of digits sorted in ascending order E.G. function("zDbc") returns “2,8,8,9” (z => 122, D=>68, b=>98, c=>99) ....i am not allowed to use any of the built-in functions

  • Write a javascript function that accepts 3 arrays and returns a string of the elements sorted...

    Write a javascript function that accepts 3 arrays and returns a string of the elements sorted in ascending value, with duplicates removed. Return all alphabetic characters in lowercase. E.G. function([ 1,2,3, d], [5, 3, 0, ‘a’], [‘a’,’d’,9]) returns “0,1,2,3,5,9,a,d” E.G. function(['w', 'i', 'H', 5], [8, 5, 9, 'c', 'Z'], [6, 4, 'a', 'b', 'y']) returns “4,5,6,8,9,a,b,c,h,i,w,y,z” we must not use ' sort, remove, split,join and any built-in fucntions

  • write an algorithm function called balance() in javascript that takes in a string and returns a...

    write an algorithm function called balance() in javascript that takes in a string and returns a strinf with balanced parantheses only. the string should be able to contain only parantheses, numbers, and letters. include comments of each portion of your code balance(“()()”) should return “()()” balance(“())”) should return “()” balance(“a(b)c”) should return “a(b)c” balance(“a(b)c())”) should return “a(b)c()”

  • Write a function called smallestLetter that takes in a string argument and returns a char. The...

    Write a function called smallestLetter that takes in a string argument and returns a char. The char that is returned by this function is the character in the string with the lowest ASCII integer code. For example: smallestLetter("Hello") returns ‘H’ which is code 72, and smallestLetter("Hello World") returns ‘ ’ (The space character) which is code 32

  • In pyhton 3.7 please 2. Write a function that takes, as an argument, either a 12-digit...

    In pyhton 3.7 please 2. Write a function that takes, as an argument, either a 12-digit positive integer n or a string consisting of 12 digits, and calculates the 13th digit (the check digit) for a 13-digit ISBN. Name this function calculateCheckDigit(n). For example, >>>calculateCheckDigit(452678904653) should return 5. As an additional example, >>>calculateCheckDigit(546654945486) should return 8. 3. Write a function that takes, as an argument, an eight-bit binary string and does the following, in this order: • Verifies that it...

  • Create Code Using C program: 1. Write a function, reverse Digit, that takes an integer as...

    Create Code Using C program: 1. Write a function, reverse Digit, that takes an integer as a parameter and returns the number with its digits reversed. For example, the value of reverseDigit (12345) is 54321; the value of reverse Digit (5600) is 65, the value of reverse Digit (7008) is 8007 and the value of reverse Digit (-532) is -235.

  • JavaScript 1. Write a function which receives one argument (string) and converts the string to uppercase....

    JavaScript 1. Write a function which receives one argument (string) and converts the string to uppercase. function('abc') // returns 'ABC' 2. Write a function that accepts an array and a value. Find and return the first array element with bigger than given value. function([5,15,4],6) //returns 15 DO NOT USE THESE IN-BUILT FUNCTIONS BELOW endsWith() includes() indexOf() lastIndexOf() localeCompare() match() repeat() replace() search() slice() split() startsWith() substr() substring() toLocaleLowerCase() toLocaleUpperCase() toLowerCase() toString() toUpperCase() trim() valueOf() trimLeft and trimRight unshift() valueOf() includes()...

  • In Javascript: Write a function named "categorize" that takes a string as a parameter and returns...

    In Javascript: Write a function named "categorize" that takes a string as a parameter and returns "short" if the input has less than 6 characters, "medium" if the input has greater than or equal to 6 but less than 7, and returns "long" if the input has greater than or equal to 7 characters. Thanks

  • LANGUAGE = C i. Write a program that takes int numbers from user until user gives...

    LANGUAGE = C i. Write a program that takes int numbers from user until user gives a sentinel value (loop terminating condition). Sort the numbers in ascending order using Insertion sort method. Sorting part should be done in different function named insertionSort(). Your code should count the number of swaps required to sort the numbers. Print the sorted list and total number of swaps that was required to sort those numbers. (4 marks) ii. In this part take another number...

  • Write a function called "phoneNumberFormat" that takes a string containing a ten-digit phone number (such as...

    Write a function called "phoneNumberFormat" that takes a string containing a ten-digit phone number (such as 5155551212) as input, convert into a more readable string with parentheses and dashes like (515)555-1212 and display it. If the input string contains more than or less than ten characters, display an error message. Note: Steps of phoneNumberFormat function can be given as follows: def phoneNumberFormat (phoneNum): 1. Let l be the length of the phoneNum 2. If 1 does not equal 10 then,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT