エントリーの編集
エントリーの編集は全ユーザーに共通の機能です。
必ずガイドラインを一読の上ご利用ください。
JavaScriptにもflatMapを! - Qiita
記事へのコメント0件
- 注目コメント
- 新着コメント
このエントリーにコメントしてみましょう。
注目コメント算出アルゴリズムの一部にLINEヤフー株式会社の「建設的コメント順位付けモデルAPI」を使用しています
- バナー広告なし
- ミュート機能あり
- ダークモード搭載
関連記事
JavaScriptにもflatMapを! - Qiita
function flatMap(xs, f) { return xs.reduce(function (ys, x) { return ys.concat(f(x)); }, []); } /... function flatMap(xs, f) { return xs.reduce(function (ys, x) { return ys.concat(f(x)); }, []); } //=> [4, 12, 20, 28, 36] console.log(flatMap([1,2,3,4,5,6,7,8,9,10], function (x) { return x % 2 === 1 ? [x << 2] : []; })); Object.defineProperty(Array.prototype, 'flatMap', { value: function (f, self) { self = self || this; return this.reduce(function (ys, x) { return ys.concat(f.call(self, x)); }, []