I am sorting an array of objects and the sorting function seems to do not have any result on the array. So it returns the same list.
I exported the array and the sorting functions to the window and execute them manually then the resulting array is well sorted.
import { connect } from "react-redux"
import DestinationsGallery from "./destinationsGallery"
import DestinationFilter from "./functions/filter"
import WindPoint from "./functions/windPoint"
import {sortCosts,sortWind, sortName} from "./functions/sort"
const getSelectedDestinations = ( catalog, filter ) => {
let paramCatalog = null
let paramSorted = null
if (catalog) {
paramCatalog = catalog
.map(spot => WindPoint(spot,filter))
.filter( item => DestinationFilter( item,filter ) )
.sort( ( a,b ) => a.name.localeCompare( b.name ) )
window.catalog = paramCatalog
window.sortCosts = sortCosts
window.sortWind = sortWind
window.sortName = sortName
console.log("Unsorted",paramCatalog)
paramSorted = paramCatalog.sort( sortName )
console.log( "Sorted name",paraSorted, paramCatalog.sort( sortName ) )
let paraSorted = paramCatalog.sort( sortWind )
console.log( "Sorted wind",paraSorted )
}
return paramSorted
}
export default connect( store => ({
destinations: getSelectedDestinations(store.kiteSpots.catalog.list, store.kiteSpots.filter),
filter: store.kiteSpots.filter,
}),null)(DestinationsGallery)
and my sorting functions are:
export const sortCosts = ( a,b ) => ( a.data.CostsRank > b.data.CostsRank? 1 : -1 )
export const sortWind = ( a,b ) => ( a.windPoint.probability > b.windPoint.probability ? 1 : -1 )
export const sortName = ( a,b ) => { return a.name > b.name ? 1 : -1 }
So I just would like the output list is correct