DEV Community

loading...

Discussion on: The 7 JavaScript Skills You Need For React (+ Practical Examples)

Collapse
belinde profile image
Franco Traversaro

Small suggestion: in the reduce() example you could skip the subsequent map() moving the jsx inside the reduce:

import React from "react";

function App() {
  const programmers = ["Reed", "John", "Jane"];

  return (
    <ul>
      {/* Returns 'Reed' */}
      {programmers.reduce(
        (acc, programmer) => programmer.startsWith("J") 
            ? acc
            : acc.concat(<li>{programmer}</li>), 
        []
      )}
    </ul>
  );
}

export default App;
Enter fullscreen mode Exit fullscreen mode