首页 > 解决方案 > 如何将数组更改为列表

问题描述

我想创建一个函数来更改数组并在打字稿中返回节点列表。假设起始索引为 0。我在代码中遇到了几个错误。

编辑代码:

export let arrayToList = (list: [number], index: number): Node<number> => {
    for (let i = list.length; i >= 0; i--) {
        if (i === list.length) {
            return cons(null);
        } else {
            return cons(list[i]);
        }
    }
    return null;
};

标签: arraystypescriptlist

解决方案


推荐阅读