JSFiddle - React, Tailwind, and code Playground

by Hugo Lopez

JavaScript

const data = [
  "#### Item 1",
  "### Item 2",
  "# Item 3",
  "## Item4",
  "# Item 5"
];

const addItemType = data.map(str => ({
  str,
  type: ["word", "sentence"][(str.match(/#/g) || []).length - 1] || "poem"
}));

console.log(addItemType);