Im trying to count letters and display it in a table. right now the table works but there too many rows and the count is incorrect.
| A | 2 | 
|---|---|
| B | 3 | 
| C | 1 | 
how can i make the output look like this?
import {
  Paper,
  Table,
  TableBody,
  TableCell,
  TableContainer,
  TableHead,
  TableRow
} from "@material-ui/core";
import "./styles.css";
const letters = ["A", "A", "B", "B", "B", "C"];
const Row = (letter: string) => (
  <TableRow>
    <TableCell>{letter}</TableCell>
    <TableCell>{letters.lastIndexOf(letter)}</TableCell>
  </TableRow>
);
export default function App() {
  return (
    <div className="App">
      <TableContainer component={Paper}>
        <Table sx={{ minWidth: 650 }} aria-label="simple table">
          <TableHead>
            <TableRow>
              <TableCell>letter</TableCell>
              <TableCell>count</TableCell>
            </TableRow>
          </TableHead>
          <TableBody>{letters.map(Row)}</TableBody>
        </Table>
      </TableContainer>
    </div>
  );
}
 
    