How to do equivalent of LINQ SelectMany() just in javascript

后端 未结 9 1472
隐瞒了意图╮
隐瞒了意图╮ 2020-12-13 16:54

Unfortunately, I don\'t have JQuery or Underscore, just pure javascript (IE9 compatible).

I\'m wanting the equivalent of SelectMany() from LINQ functionality.

<
9条回答
  •  情深已故
    2020-12-13 17:22

    For those a while later, understanding javascript but still want a simple Typed SelectMany method in Typescript:

    function selectMany(input: TIn[], selectListFn: (t: TIn) => TOut[]): TOut[] {
      return input.reduce((out, inx) => {
        out.push(...selectListFn(inx));
        return out;
      }, new Array());
    }
    

提交回复
热议问题