Implement selection sort in JavaScript.