Skip to content

Commit

Permalink
fix typo in handleSort function
Browse files Browse the repository at this point in the history
  • Loading branch information
yarocruz committed May 23, 2020
1 parent 7b3ef87 commit da64816
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ function App() {
const [ data, setEmployees ] = useState(employees);

function handleSearchTerm(event) {
event.preventDefault();
setSearchTerm(event.target.value)
}

function handleSortByName(event) {
event.preventDefault();
function handleSortByName() {
// sort array ascending or descending by first name
if (!sorted) {
setEmployees(data.sort((a, b) => (a.name > b.name) ? 1 : -1));
Expand All @@ -28,14 +26,13 @@ function App() {
}
}

function handleSortByDept(event) {
event.preventDefault();
function handleSortByDept() {
// sort array ascending or descending by dept name
if (!sorted) {
setEmployees(data.sort((a, b) => (a.department > b.department) ? 1 : -1));
setSorted(true);
} else {
setEmployees(data.sort((a, b) => (a.department > b.department) ? -11 : 1));
setEmployees(data.sort((a, b) => (a.department > b.department) ? -1 : 1));
setSorted(false);
}
}
Expand Down

0 comments on commit da64816

Please sign in to comment.