const singers = [
{ name: 'Steven Tyler', band: 'Aerosmith', born: 1948 },
{ name: 'Karen Carpenter', band: 'The Carpenters', born: 1950 },
{ name: 'Kurt Cobain', band: 'Nirvana', born: 1967 },
{ name: 'Stevie Nicks', band: 'Fleetwood Mac', born: 1948 },
];
function compareValues(key, order = 'asc') {
return function innerSort(a, b) {
if (!a.hasOwnProperty(key) || !b.hasOwnProperty(key)) {
// property doesn't exist on either object
return 0;
}
const varA = (typeof a[key] === 'string')
? a[key].toUpperCase() : a[key];
const varB = (typeof b[key] === 'string')
? b[key].toUpperCase() : b[key];
let comparison = 0;
if (varA > varB) {
comparison = 1;
} else if (varA < varB) {
comparison = -1;
}
return (
(order === 'desc') ? (comparison * -1) : comparison
);
};
}
// array is sorted by band, in ascending order by default
singers.sort(compareValues('band'));
// array is sorted by band in descending order
singers.sort(compareValues('band', 'desc'));
this.props.navigation.navigate('Details', {
itemId: 86,
otherParam: 'anything you want here',
});
export const endWorkingDay = () => (dispatch, getState) => {
return axios.post(`${API_ROOT}/api/Account/EndWork?date=${endDate}&tradePointId=${id}&lat=${currentLat}&long=${currentLong}`,
null,
{
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json;charset=UTF-8",
},
}
)
.then(
response => {
if (response.status === 200) {
dispatch({
type: SET_END_WORK_DATA,
payload: {
endWorkData: {
tradePointId: id,
lat: currentLat,
long: currentLong,
date: dateformat(new Date(), "yyyy-mm-dd"),
synced: true,
},
},
})
axios({
method: 'post',
url: `${ROOT_URL}/posts`,
data: {
},
headers: { authorization: localStorage.getItem("token") }
})