Swift Sort Array Javascript Iteration