-2

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.

2
  • Please provide enough code so others can better understand or reproduce the problem. Commented May 21, 2022 at 13:07
  • This seems to be an assignment from school or other. Please try your own implementation before outsourcing to stackoverflow Commented May 21, 2022 at 13:33

1 Answer 1

-1

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()

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.