javascript ndarray functions