subject

In an array, we can swap the elements at any two indices in a single operation called a move. For example, if our array is a = {17, 4, 8}, we can swap a0 = 17 and a2 = 8 to get a = {8,4,17} in a single move. We want to custom-sort an array such that all of the even elements are at the beginning of the array and all of the odd elements are at the end of the array.

Complete the function moves. The function must return the minimum of the moves it takes to sort an array of integers with all even elements at earlier indexes that any odd element.

Note: the order of the elements within even or odd doesn’t matter

Sample input 4,13,10,21,20

Sample output 1

In JavaScript

function moves(a) {

//you code here

}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 03:20
Which of these is a benefit of social networking? oa. hiding your true identity from friendsob. avoiding talking to people in personoc. spending time with friends instead of studyingod. connecting with new people
Answers: 2
question
Computers and Technology, 22.06.2019 11:00
Lisa’s company, abc ltd., lost its biggest client and is now facing a financial crunch. most of her colleagues have resigned, but lisa decides to stay with the company and assist the management in overcoming the financial situation. which quality is lisa demonstrating? a. self-management b. cooperativeness c. responsibility d. loyalty
Answers: 2
question
Computers and Technology, 22.06.2019 15:30
Which of the following examples has four beats in each measure?
Answers: 2
question
Computers and Technology, 22.06.2019 17:00
Which of the following is not contained on the slide show toolbar? a. next button b. slide button c. close button d. pen tool
Answers: 1
You know the right answer?
In an array, we can swap the elements at any two indices in a single operation called a move. For ex...
Questions
question
Mathematics, 30.03.2020 22:11
question
Mathematics, 30.03.2020 22:11
Questions on the website: 13722362