I have an array of URLs, and I want the current URL to be the top most member, and the rest in alphabetical order. The links
array starts off in alphabetical order ascending.
The links
array looks like this...
var links = [
'http://example.com',
'http://example.net',
'http://stackoverflow.com'
];
But my current URL may be http://stackoverflow.com/questions
. This should match the 2nd member above.
What is the best way to achieve this?
Thanks
Why not this simple approach?
Array.splice(Array.indexOf(url), 1)
Array.unshift()
to prepend the current URLLess checks, only a simple splice and unshift.
Update
If you need to match the current domain.
This is untested, but in theory it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With