Modify the function to return a copy of the given array sorted in ascending order (1, 2, 3, etc). Do not modify the original array.
function copyAndSortNumbers(numbers) {
}
/* Do not modify code below this line */
const original = [1, 7, 3, 5];
const sortedCopy = copyAndSortNumbers(original);
console.log(original, '<-- should be [1, 7, 3, 5]');
console.log(sortedCopy, '<-- should be [1, 3, 5, 7]');
function copyAndSortNumbers(numbers) { result = [...numbers]; result.sort(); return result; } /* Do not modify code below this line */ const original = [1, 7, 3, 5]; const sortedCopy = copyAndSortNumbers(original); console.log(original, '<-- should be [1, 7, 3, 5]'); console.log(sortedCopy, '<-- should be [1, 3, 5, 7]');
Modify the function to return a copy of the given array sorted in ascending order (1,...
Modify the function to push the given item onto the end of the array and return the array. function addItemToArray(array, item) { } const items = addItemToArray([1, 2, 3], 4); console.log(items, '<-- should equal [1, 2, 3, 4]');
using c++ Write a function that returns true if a given integer array is sorted(in ascending order) and false if it is not. The function should perform no more than "size" comparisons. bool isSorted(int A[], int size);
Given a sorted (in ascending order) integer array nums of n elements and a target value, write a method to perform a binary search for a target value in nums. If target exists, then return its index, otherwise return -1. Analyze the running time, T(n). public int search(int[] nums, int target) { // YOUR CODE GOES HERE } // end search
IN JAVA please Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. Your code will be tested for runtime. Code which does not output a result in logarithmic time (making roughly log(2) N comparisons) will fail the tests. A sample main function is provided so that you may test your code on sample inputs. For testing purposes, the...
Implement a method to build an AVL tree out of a sorted (ascending order) array of unique integers, with the fastest possible big O running time. You may implement private helper methods as necessary. If your code builds a tree that is other than an AVL tree, you will not get any credit. If your code builds an AVL tree, but is not the fastest big O implementation, you will get at most 12 points. You may use any of...
C programing Write a program to sort numbers in either descending or ascending order. The program should ask the user to enter positive integer numbers one at a time(hiting the enter key after each one) The last number entered by the user should be -1, to indicate no further numbers will be entered. Store the numbers in an array, and then ask the user how to sort the numbers (either descending or ascending). Call a function void sortnumbers ( int...
Modify your asm code further so that you can copy the entire array of numbers (1 to 100) to a different location in the memory (starting from 0x0000_0200h location, i.e. offset of 200h). Lab6.s (MIPS assemblv code .data tmpval: .word 5 globl main .text main # above codes are mandat ry (entry to main function) ######### only modify the c des below ########### # L ad address # initialize N addiu ŞvO, $zero, 1 loopl SW $vO, 0 ($s0) $t0,...
Write a templated function sumList that will take in an array of any type and the length of the array. It should add all the elements in the array and return the total. Hint: you can declare a variable sum of type T and initialize it like this: T sum {}; The {} are the best way to make sure that numbers get set to 0, a string gets created as empty etc... #include <iostream> using namespace std; //Do not...
(C++ program )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 the 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....
Description: Write a complete C++ program that will do the following: 1. Declare an array of 30 elements 2. Set the array to random numbers between 0 to 100 inclusive. Don't seed the random number generator. 3. Output the array. 4. Sort the array in ascending order using the selection sort. 5. Output the sorted array. Required IO: Array by F. Last Original: 1 5 ... 2 10 + Sorted: 1 2 ... 5 10 ( +