Create a program that will allow you to enter a number of integers to input. Then input values for those integers and store them into an array(Array A). After that, create another array(Array B) that will store the doubled value of elements from the first array. Display the two arrays. Display also the ascending order of the first array and the descending order of the second array.
-
Please provide enough code so others can better understand or reproduce the problem.Community– Community Bot2022-05-21 13:07:50 +00:00Commented May 21, 2022 at 13:07
-
This seems to be an assignment from school or other. Please try your own implementation before outsourcing to stackoverflowuser3133– user31332022-05-21 13:33:40 +00:00Commented May 21, 2022 at 13:33
Add a comment
|
1 Answer
look into array mapping (and arrow functions to make life easier)
e.g. var newNumbers = numbers.map(n => n*2) Will return another array with all the elements of the numbers array doubled.
also look into sort() and reverse()
e.g. newNumbers.sort(function(a, b){return a-b}).reverse(); Will sort the array and reverse its order.
You need this comparison thing in the sort() because of they way numbers are processed with sort()