El siguiente programa realiza una piramide de X's de acuerdo a un solo valor que define el numero de niveles:
por ejemplo:
3:
x
xxx
xxxxx
5:
x
xxx
xxxxx
xxxxxxx
xxxxxxxxx
No deben de ser numeros negativos ni 0
function piramids(numero){
var pisos = [];
var espacio = " ";
var caracter = "x";
var coespacios = numero - 1;
for(let i = 0; i < numero; i++){
pisos[i]="";
var cocaracter = ((i + 1)*2)-1;
for(let e = 0; e < coespacios; e++){
pisos[i] += espacio;
}
for(let c = 0; c < cocaracter; c++){
pisos[i] += caracter;
}
coespacios --;
}
for(let f = 0; f < numero; f++){
console.log(pisos[f]);
}
}
piramids(5);
/*var parte = "que";
var parte2 = "so";
const unir = parte + parte2;
console.log(unir);*/
// Since Node 10, we're using Mocha.
// You can use `chai` for assertions.
const chai = require("chai");
const assert = chai.assert;
// Uncomment the following line to disable truncating failure messages for deep equals, do:
// chai.config.truncateThreshold = 0;
// Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
// Uncomment the following to use the old assertions:
// const Test = require("@codewars/test-compat");
describe("Solution", function() {
it("should test for something", function() {
// Test.assertEquals(1 + 1, 2);
// assert.strictEqual(1 + 1, 2);
});
});