-1

I have an array like [c, a, b]. The array is dynamic, and the possible values for array are a, b, c, d, and e. And I want to sort the array in a specific order like b,d,c,a,e.

ie. My desired output is [b, d, a] in this case

If input is [e, b] the output is [b, e] like that. Is there any single method for this?

4
  • custom order? or do you mean random order? Is there any pattern? Commented Mar 29, 2019 at 8:59
  • Why you need above kind of sorting. Please specify a reason and multiple test cases. Commented Mar 29, 2019 at 9:00
  • @Mukyuu yes random order Commented Mar 29, 2019 at 9:09
  • You can check the following: stackoverflow.com/questions/2450954/… Commented Mar 29, 2019 at 9:10

1 Answer 1

-1

You can pass a callback to an array sort function (c.f. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Syntax )

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.