Sort in decreasing order ionic 2

Sort in decreasing order ionic 2

Can’t find your question lmao.

1 Like

what imao? I do not understand your message

You didn’t ask anything. What do you want to know from us?

I want to display an integer array in descending order
voici le code

this.fakeArray = new Array(this.visitinfo.queueSize);

  <div *ngFor="let a of fakeArray; let index = index  " class="col center-text queue-itm parent-center" [ngClass]="{empty:isEmptyQueueItem(), selected:hilightSelctedPosition(), other:!hilightSelctedPosition() && !isEmptyQueueItem()}">
        <div [ngClass]="{'child-center': true, 'center-content' : hilightSelctedPosition()}">
            <div class="ellipsis__content">{{ index+1 }}</div>
        </div>

No matter how you sort in this scenario, it will always go from low to high, since all you’re doing is printing the index of the item, and not using anything else from the array. If you reverse it, the index will still start from 0. Could do

{{ visitinfo.queueSize - index }}

That should do it, in this case.

Edit

Also when you’re using Array in this fashion, you’ll actually end up with an array that looks like this

[ null, null, null, null, ... ]

and not

[ 0, 1, 2, 3, 4, ... ]

Ok how to fill it [ 0, 1, 2, 3, 4, ... ]

then

this.fakeArray = (() => {
	let startFromZero = false;
	let array = Array(this.visitinfo.queueSize);

	for(let i = 0; i < array.length; i++) {
		array[i] = i + (startFromZero ? 0 : 1);
	}

	return array.sort(function(a, b) {
		return b - a;
	});
})(); // Updated for less confusion with variables

I’m sure there is a better place to put that, but this should do it.

<div *ngFor="let num of fakeArray; let i = index">
    {{ num }}
</div>

Thank you very much it works