Sorting Array Issue


#1

I am sorting array with function
sortArray(x){
if(x == ‘Hour’){
this.temp_bitcoin = this.bitcoinData.sort((a: any, b: any) => {
return b[‘percent_change_1h’] - a[‘percent_change_1h’];
});
this.showSomeData(this.temp_bitcoin);

    }else if(x == 'Day'){
        this.temp_bitcoin=   this.bitcoinData.sort((a: any, b: any) => {
            return  b['percent_change_24h'] - a['percent_change_24h'];
        });
        this.showSomeData(this.temp_bitcoin)


    }else if(x == 'Week'){
        this.temp_bitcoin =   this.bitcoinData.sort((a: any, b: any) => {
            return  b['percent_change_7d'] - a['percent_change_7d'];
        });
        this.showSomeData(this.temp_bitcoin)

    }
    return this.temp_bitcoin;
}

now i want to show only 50 items in the array. But hte view is not updating the array as sorted . Like initially the array will be sorted hourly but after its week the array title will not change only its value updates


#2

Why is this in the ionic-native category?


#3

@rapropos :cry:
If you could help then please do it. Its ionic in anyways


#4

Please provide a Sample Array which you are working with, then it will be easier for us to debug.

Also, indent/format your code properly for better readability.


#5

@saidatta123

the array is actually the response of https://api.coinmarketcap.com/v1/ticker/ the link


#6

@saidatta123

the array is actually the response of https://api.coinmarketcap.com/v1/ticker/ the link
[/quote]

i am trying to use infinite scroll with 50 data each. But array was not refreshing on sorting