Use for-of instead of forEach (#3583)

Co-authored-by: syuilo <syuilotan@yahoo.co.jp>
Co-authored-by: Acid Chicken (硫酸鶏) <root@acid-chicken.com>
This commit is contained in:
Aya Morisawa
2018-12-11 20:36:55 +09:00
committed by GitHub
parent 30c53e9ee0
commit 125849673a
84 changed files with 345 additions and 283 deletions

View File

@ -47,10 +47,7 @@ export default define(meta, (ps) => new Promise(async (res, rej) => {
}> = [];
// カウント
data.map(x => x._id).forEach(x => {
// ブラックリストに登録されているタグなら弾く
if (hidedTags.includes(x.tag)) return;
for (const x of data.map(x => x._id).filter(x => !hidedTags.includes(x.tag))) {
const i = tags.findIndex(tag => tag.name == x.tag);
if (i != -1) {
tags[i].count++;
@ -60,7 +57,7 @@ export default define(meta, (ps) => new Promise(async (res, rej) => {
count: 1
});
}
});
}
// タグを人気順に並べ替え
tags.sort((a, b) => b.count - a.count);

View File

@ -100,14 +100,14 @@ export default define(meta, (ps, user) => new Promise(async (res, rej) => {
Note.find({
'_files._id': file._id
}).then(notes => {
notes.forEach(note => {
for (const note of notes) {
note._files[note._files.findIndex(f => f._id.equals(file._id))] = file;
Note.update({ _id: note._id }, {
$set: {
_files: note._files
}
});
});
}
});
// Serialize

View File

@ -25,9 +25,8 @@ export default define(meta, (ps, user) => new Promise(async (res, rej) => {
loopedBoard: game.settings.loopedBoard
});
game.logs.forEach(log => {
for (const log of game.logs)
o.put(log.color, log.pos);
});
const packed = await pack(game, user);

View File

@ -58,10 +58,7 @@ export default define(meta, () => new Promise(async (res, rej) => {
}> = [];
// カウント
data.map(x => x._id).forEach(x => {
// ブラックリストに登録されているタグなら弾く
if (hidedTags.includes(x.tag)) return;
for (const x of data.map(x => x._id).filter(x => !hidedTags.includes(x.tag))) {
const i = tags.findIndex(tag => tag.name == x.tag);
if (i != -1) {
tags[i].count++;
@ -71,7 +68,7 @@ export default define(meta, () => new Promise(async (res, rej) => {
count: 1
});
}
});
}
// 最低要求投稿者数を下回るならカットする
const limitedTags = tags.filter(tag => tag.count >= requiredUsers);

View File

@ -59,11 +59,11 @@ export default define(meta, (ps, user) => new Promise(async (res, rej) => {
//#region Deck
if (widget == null && user.clientSettings.deck && user.clientSettings.deck.columns) {
const deck = user.clientSettings.deck;
deck.columns.filter((c: any) => c.type == 'widgets').forEach((c: any) => {
c.widgets.forEach((w: any) => {
if (w.id == ps.id) widget = w;
});
});
for (const c of deck.columns.filter((c: any) => c.type == 'widgets')) {
for (const w of c.widgets.filter((w: any) => w.id == ps.id)) {
widget = w;
}
}
if (widget) {
widget.data = ps.data;

View File

@ -91,5 +91,7 @@ export default define(meta, (ps, user) => new Promise(async (res, rej) => {
res(await packMany(mentions, user));
mentions.forEach(note => read(user._id, note._id));
for (const note of mentions) {
read(user._id, note._id);
}
}));

View File

@ -102,12 +102,12 @@ export default define(meta, (ps, user) => new Promise(async (res, rej) => {
}
})
.then(watchers => {
watchers.forEach(watcher => {
for (const watcher of watchers) {
notify(watcher.userId, user._id, 'poll_vote', {
noteId: note._id,
choice: ps.choice
});
});
}
});
// この投稿をWatchする

View File

@ -2,6 +2,7 @@ import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
import Note from '../../../../models/note';
import User, { pack } from '../../../../models/user';
import define from '../../define';
import { maximum } from '../../../../prelude/array';
export const meta = {
requireCredential: false,
@ -77,20 +78,16 @@ export default define(meta, (ps, me) => new Promise(async (res, rej) => {
const repliedUsers: any = {};
// Extract replies from recent notes
replyTargetNotes.forEach(note => {
const userId = note.userId.toString();
for (const userId of replyTargetNotes.map(x => x.userId.toString())) {
if (repliedUsers[userId]) {
repliedUsers[userId]++;
} else {
repliedUsers[userId] = 1;
}
});
}
// Calc peak
let peak = 0;
Object.keys(repliedUsers).forEach(user => {
if (repliedUsers[user] > peak) peak = repliedUsers[user];
});
const peak = maximum(Object.values(repliedUsers));
// Sort replies by frequency
const repliedUsersSorted = Object.keys(repliedUsers).sort((a, b) => repliedUsers[b] - repliedUsers[a]);