I'm trying to sort a string based on the length of its items
This is the array
const quotes = [
{ref1: 'CE255X', price_u: '1024100'},
{ref1: 'M-TK137', price_u: '65400'},
{ref1: '126A', price_u: '242300'},
{ref1: 'M-CE278A', price_u: '35000'},
{ref1: 'M-Q2612A', price_u: '35000'},
{ref1: 'M-Q7551X', price_u: '130002'},
{ref1: '507A', price_u: '905300'},
{ref1: 'M-35A/36A/85A/78A', price_u: '35000'}
];
This is the code I have attempted
let i = 0;
let details = '';
for (let index = 0; index < quotes.length; index++) {
i++;
if (quotes[index].ref1.length <= 50) {
details += i + '.' + quotes[index].ref1.padEnd(38, '#');
details += quotes[index].price_u + '\n';
}
}
console.log(details);
If the data displays like this
1.CE255X########1024100
2.M-TK137#######65400
3.126A########242300
4.M-CE278A#######35000
5.M-Q2612A#######35000
6.M-Q7551X#######130002
7.507A########905300
8.M-35A/36A/85A/78A####35000
I would like to rearrange it by replacing the #
with white spaces
1.CE255X################1024100
2.M-TK137############65400
3.126A##############242300
4.M-CE278A############35000
5.M-Q2612A############35000
6.M-Q7551X###########130002
7.507A##############905300
8.M-35A/36A/85A/78A####35000
Any assistance would be greatly appreciated