jherax/array-sort-by

TypeError: Cannot assign to read only property '28' of string ' **Bea ~#2005** 18402 moons

DarkenLM opened this issue · 1 comments

Hello!

I was trying to use your module to sort in descending order my leaderboard in quick.db, but I couldn't. It gives me this error:
gtrkhyrkth

Why?

Here is my leaderboard code:
`const Discord = require("discord.js");
const db = require('quick.db');
var sortBy = require('array-sort-by');
var currencyFormatter = require('currency-formatter'); //For currency
var fs = require('fs'); //FileSystem

exports.run = async (bot, message, args) => {
const resp = await db.startsWith('moons', { sort: '.data'});
resp.length = 10;
let finalOutput = ' ';
for (var i in resp) {
var us = bot.users.get(resp[i].ID.split("")[1])
//moons
${us.id}
let Moonsdisplay;
let TotalMoons;
let moons = await db.fetch(moons_${us.id})
if (moons === null) db.set(moons_${us.id}, 0);
else TotalMoons = moons;
if (TotalMoons === undefined) TotalMoons = 0;
let amount = parseInt(args.join(' '));

if (TotalMoons > 1000000) { Moonsdisplay = 'Infinitas' } else {Moonsdisplay = TotalMoons}
var usermoons = Moonsdisplay;
finalOutput += **${bot.users.get(resp[i].ID.split("_")[1]).tag}** + ' ' + usermoons + moons \n; // - Moons: ${resp[i].data}
console.log(finalOutput)
var arr = ['teste', 'do', 'caralho']
var msgtosend = await sortBy(finalOutput, item => 'desc:' + item)
}
message.channel.send({
embed: {
"description": msgtosend,
"title": 'Top de Moons',
"color": 16777215
}
})
}
module.exports.command = {
name: 'topmoons',
aliases: ['leaderboard'],
description: 'Veja os mais ricos do servidor!',
category: "Economia",
usage: 's!topmoons',
enabled: false
}`

Please fix this.

Hi, there are no problems with the lib, but you have the following line:

var msgtosend = await sortBy(finalOutput, item => 'desc:' + item)

The problem is you are using await on sortBy which is not a Promise, also the first argument that sortBy receives is an Array; make sure your variable finalOutput is a valid Array.

See strings: descending order.

It should be used something like this:

// descending order
var orderedItems = sortBy(sourceArray, item => `desc:${item}`)