From 3cace734c70c752c57ed9a0057aef4d7ef788528 Mon Sep 17 00:00:00 2001 From: Aya Morisawa <AyaMorisawa4869@gmail.com> Date: Thu, 6 Sep 2018 21:31:15 +0900 Subject: [PATCH] Add concat function (#2640) --- src/client/app/desktop/views/pages/welcome.vue | 5 +++-- src/client/app/mobile/views/pages/welcome.vue | 5 +++-- src/games/reversi/core.ts | 4 ++-- src/prelude/array.ts | 8 ++++++-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/client/app/desktop/views/pages/welcome.vue b/src/client/app/desktop/views/pages/welcome.vue index 0138fde273..7409f6c9b6 100644 --- a/src/client/app/desktop/views/pages/welcome.vue +++ b/src/client/app/desktop/views/pages/welcome.vue @@ -85,6 +85,7 @@ <script lang="ts"> import Vue from 'vue'; import { host, copyright } from '../../../config'; +import { concat } from '../../../../../prelude/array'; export default Vue.extend({ data() { @@ -119,8 +120,8 @@ export default Vue.extend({ (this as any).api('notes/local-timeline', { fileType: image, limit: 6 - }).then(notes => { - const files = [].concat(...notes.map(n => n.files)); + }).then((notes: any[]) => { + const files = concat(notes.map((n: any): any[] => n.files)); this.photos = files.filter(f => image.includes(f.type)).slice(0, 6); }); }, diff --git a/src/client/app/mobile/views/pages/welcome.vue b/src/client/app/mobile/views/pages/welcome.vue index 1856731d8a..7446cc700f 100644 --- a/src/client/app/mobile/views/pages/welcome.vue +++ b/src/client/app/mobile/views/pages/welcome.vue @@ -40,6 +40,7 @@ <script lang="ts"> import Vue from 'vue'; import { apiUrl, copyright, host } from '../../../config'; +import { concat } from '../../../../../prelude/array'; export default Vue.extend({ data() { @@ -79,8 +80,8 @@ export default Vue.extend({ (this as any).api('notes/local-timeline', { fileType: image, limit: 6 - }).then(notes => { - const files = [].concat(...notes.map(n => n.files)); + }).then((notes: any[]) => { + const files = concat(notes.map((n: any): any[] => n.files)); this.photos = files.filter(f => image.includes(f.type)).slice(0, 6); }); } diff --git a/src/games/reversi/core.ts b/src/games/reversi/core.ts index e2a2289f18..3ca9d052af 100644 --- a/src/games/reversi/core.ts +++ b/src/games/reversi/core.ts @@ -1,4 +1,4 @@ -import { count, countIf } from "../../prelude/array"; +import { count, concat } from "../../prelude/array"; // MISSKEY REVERSI ENGINE @@ -286,7 +286,7 @@ export default class Reversi { } }; - return [].concat(...diffVectors.map(effectsInLine)); + return concat(diffVectors.map(effectsInLine)); } /** diff --git a/src/prelude/array.ts b/src/prelude/array.ts index aee17640ed..9a3c266d6d 100644 --- a/src/prelude/array.ts +++ b/src/prelude/array.ts @@ -6,6 +6,10 @@ export function count<T>(x: T, xs: T[]): number { return countIf(y => x === y, xs); } -export function intersperse<T>(sep: T, xs: T[]): T[] { - return [].concat(...xs.map(x => [sep, x])).slice(1); +export function concat<T>(xss: T[][]): T[] { + return ([] as T[]).concat(...xss); +} + +export function intersperse<T>(sep: T, xs: T[]): T[] { + return concat(xs.map(x => [sep, x])).slice(1); }