Commit c558236d authored by nanahira's avatar nanahira

fix

parent 8694d45b
...@@ -53,18 +53,18 @@ async function openDatabase() { ...@@ -53,18 +53,18 @@ async function openDatabase() {
} }
function getMedianCode(cards: Card[]) { function getMedianCode(cards: Card[]) {
const sortedCards = cards.sort((a, b) => a.id - b.id); const sortedCards = cards;
const len = sortedCards.length; const len = sortedCards.length;
if (len % 2 === 0) { if (len % 2 === 0) {
return Math.floor((sortedCards[len / 2].id + sortedCards[len / 2 + 1].id) / 2); return Math.floor((sortedCards[len / 2 - 1].id + sortedCards[len / 2].id) / 2);
} else { } else {
return sortedCards[(len + 1) / 2].id; return sortedCards[(len + 1) / 2 - 1].id;
} }
} }
async function queryCards(queryInfo: QueryInfo) { async function queryCards(queryInfo: QueryInfo) {
const replacedWhere = replaceWhereClause(queryInfo.where); const replacedWhere = replaceWhereClause(queryInfo.where);
const cards: Card[] = await db.all(`select datas.id,texts.name from datas,texts where datas.id = texts.id and datas.type & 0x4000 = 0 and datas.id > ? and datas.id <= ? ${replacedWhere}`, [queryInfo.lower, queryInfo.upper]); const cards: Card[] = await db.all(`select datas.id,texts.name from datas,texts where datas.id = texts.id and datas.type & 0x4000 = 0 and datas.id > ? and datas.id <= ? ${replacedWhere} order by datas.id asc`, [queryInfo.lower, queryInfo.upper]);
return cards; return cards;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment