-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?

PranavPinarayi
  • 3,037
  • 5
  • 21
  • 32

1 Answers1

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

Christophe
  • 408
  • 2
  • 10