Porting pythonic array methods to JavaScript