JSFiddle - React, Tailwind, and code Playground
by ravan
HTML
<input id="num" type="text" placeholder="Número" /> <input id="btn" type="button" value="Gerar!" /><br /><br />
<span id="result"></span>
JavaScript
function triangulo(n) {
s = [[1]];
for (i = 1; i <= n; i++) {
s[i] = [];
s[i][0] = s[i][i] = 1;
for (j = 1; j < i; j++) {
s[i][j] = (s[i - 1][j] | 0) + (s[i - 1][j - 1] | 0);
}
}
return s.join('<br />').replace(/,/g,' ');
}
/* só para parte visual */
document.getElementById("btn").onclick = function() {
num = document.getElementById("num").value;
document.getElementById("result").innerHTML = triangulo(num);
}