Python Array Slice Function Javascript Code