0

The spread operator is very powerful with arrays but I find a hard time with duplication. I tried using Object.assign which has been successful at times, but others has given me weird results.

Any suggestiosn for an es6 way to use spread operator to concat arrays and deduplicate?

I am specifically using it for my Redux store:

export default function reducer(state = initialState, action = {}) {
  switch (action.type) {
    case SOCKET_SUCCESS:
      return {
        ...state,
        loading: false,
        loaded: true,
        result: [...state.result, action.result.notification].sort((prev, next) => moment(prev.createdAt).isBefore(moment(next.createdAt)) ? 1 : -1)
      };
...
Mohamed El Mahallawy
  • 13,024
  • 13
  • 52
  • 84

0 Answers0