Some javascript algorithms implementation