TypeScript

by Lloyd Atkinson

HTML

<div id="app"></div>

CSS

/* body {
  background: #20262E;
  padding: 20px;
  font-family: Helvetica;
}

#app {
  background: #fff;
  border-radius: 4px;
  padding: 20px;
  transition: all 0.2s;
  text-align: center;
}
 */

TypeScript

const mapArray = (data: any, map: (item: any, index?: number) => string) => {
    const nodes = data.map((arrayItem, arrayIndex) => map(arrayItem, arrayIndex));

    for (const node of nodes) {
        document.createElement(node);
    }
};


const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

mapArray(numbers, (item) => 'div');