This commit is contained in:
neko
2022-06-15 12:22:45 +03:00
parent d0237fd2db
commit 86f6b191d2
6 changed files with 140 additions and 1 deletions

View File

@@ -0,0 +1,21 @@
import {UserType} from '../HW8'
type ActionType = {type: 'sort', payload: 'up' | 'down'} | {type: 'check', payload: number}
export const homeWorkReducer = (state: UserType[], action: ActionType): UserType[] => { // need to fix any
switch (action.type) { // делают студенты
case 'sort': {
const newState = [...state].sort((a, b) => {
if (a.name > b.name) return 1
else if (a.name < b.name) return -1
else return 0
})
return action.payload === 'up' ? newState : newState.reverse()
}
case 'check': {
return state.filter(a => a.age >= action.payload)
}
default: return state
}
}