react.dev icon indicating copy to clipboard operation
react.dev copied to clipboard

docs: Add test scenario to exercise in queueing-a-series-of-state-updates.md

Open santiph opened this issue 1 year ago • 1 comments

I've found a wrong solution through a reduce() operation when solving this exercise as follows:

export function getFinalState(baseState, queue) {
  let finalState = queue.reduce((accumulator, currentChange) => {
    if ('function' === typeof currentChange) {
      return currentChange(accumulator);
    } else {
      return baseState + currentChange;
    }
  }, baseState);

  return finalState;
}

All tests were passing successfully. The return statement for queued numbers should've been this instead: return currentChange;

This change introduces a new test case to fail in this case :')

santiph avatar Nov 18 '23 19:11 santiph

Size changes

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

github-actions[bot] avatar Nov 18 '23 19:11 github-actions[bot]