Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

209
Vistas
How to find out below solution in JavaScript

I am a new web developer and need assistance generating a given output to a problem:

var totalNumberofRows = 5; 
var output = '';
for (var i = 1; i <= totalNumberofRows; i++) {
    for (var j = 1; j <= i; j++) {
        output +=  i;
     }
    console.log(output+' ');
    output = '';
}

Output:

1
22
333
4444
55555 

Expected Output:

1
22
333
55555
88888888

How would I be able to make my code produce the target output?

almost 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

For non-sequential numbers you could use an array with the String.repeat method:

[1, 2, 3, 5, 8].forEach(n => console.log(n.toString().repeat(n)));

almost 4 years ago · Santiago Trujillo Denunciar

0

If you want to output the fibonachi sequence you can do :

let current = 1
let last = 0

for (let i = 0; i < 5; i++) {
  console.log(Array(current+last).fill(current+last).join(''))
  let toLast = current
  current += last
  last = toLast
}

almost 4 years ago · Santiago Trujillo Denunciar

0

Have you intended something similar to the Fibonacci sequence?

var totalNumberofRows = 5;
var output = '';

for (var i = 1; i <= totalNumberofRows; i++) {
    var next = fibo(i + 1);
    
    for (var j = 1; j <= next; j++) {
        output += next;
    }

    console.log(output + ' ');
    output = '';
}

function fibo(n) {
  let result = [0, 1];

  for (let i = 2; i <= n; i++) {
    const a = result[i - 1];
    const b = result[i - 2];

    result.push(a + b);
  }

  return result[n];
}

almost 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda