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(string => {
const match = (string.match(/#/g) || []).length; // Count the number of '#'
let type =
match == 0 || match == 1 ? "word"
:match === 2? "sentence"
: "poem";
return { string, type };
});
console.log(addItemType);