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
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks
//required method
function stringToSortedDigits(text){
//creating an array to store last digits of ascii codes of text
var arr=[];
//looping through text
for(var i=0;i<text.length;i++){
//getting ascii code of character at index i
var ascii_code=text.charCodeAt(i);
//performing modulo operation by 10 to get the last digit
var last_digit=ascii_code%10;
//adding last digit to array
arr.push(last_digit);
}
//now sorting the array in ascending order using bubble sort algorithm
for(var i=0;i<arr.length;i++){
for(var j=0;j<arr.length-1;j++){
if(arr[j]>arr[j+1]){
//swapping elements at index j and j+1
var temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
//now appending the array to an empty string and returning it
var result=""+arr;
return result;
}
//testing
alert(stringToSortedDigits("bzcD")); //should display 2,8,8,9
Write a function in Java Script that accepts a string. The function takes the last digit...
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)
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
C++ Write a function named “hasDescendingDigits” that accepts a string of numbers. It returns true if the string contains the digits in descending order. The function can ignore (e.g. skip checking) all the characters that are not digits in the string. Empty string will return false. For example, string of “95421” or “862” or “8622” or “88” or “9” will return true and string of “95423” or “889” or “9445” or “449” or “” will return false.
python
1. Write a function that takes in a string and returns the string sorted For example, "cat" becomes "act", "dog" becomes "dgo" Hint: You might need to use the functions join and sorted
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 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...
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,...
CODE THE FOLLOWING FUNCTIONS IN JAVASCRIPT (USE OF THE
ABOVE MENTIONED IN BUILT FUNCTIONS IS NOT ALLOWED)
Write a function 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
Write a function that accepts two arguments (a...
Design and implement a Java program (name it PasswordTest) that accepts a string from the user and evaluates it as a password, giving it a valid or invalid verdict A good password will be at least 8 characters and includes at least one lower-case letter, at least one upper-case letter, at least one digit, and at least one character that is neither a letter nor a digit. Your program will need to check each character in the string in order...
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.