Array filled with undefined elements

Array filled with undefined elements
0.0 0

#1
function permAlone(str) {
  var num = 0;
  function factorialize(num) {
  var sum = 1;
  for (i=1;i<=num;i++){
    sum = sum*i;
  }
  return sum;
}
  str = str.split("");
  var options = [];
  var combos = [];
  for(i=0;i<str.length;i++){
    options[i] = str.slice();
    //console.log(str[i]);//????
    for(j=0;j<(factorialize(str.length-1));j++){
      combos[j] = str[i];
    }
  }
  console.log(combos);
  function choose(acc,curr,i){
    
  }
  return num;
}

When I run this code combos becomes an array containing all undefined items. It has the correct length. When I console.log(str[i]) I get only the first element of str. When I console.log(str) I get the whole str once, same when I console.log(str[#]) with any number. I’m confused as to why this happens… What am I missing?


#2

which problem are you trying to solve?
if this, then i think you are over thinking it.

spoiler%20alert

spoiler code below

function factorialize(num) {
    var a = 1;
      for (i = 1; i <= num; i++)
      {
        a = a * i;
      }
      num = a;
      return num;
    }
factorialize(20);

#3

I’m trying to solve “No repeats please”. I just used my code from “Factorialize a number” to get the factorial of str.length-1


#4

sorry i haven’t made it to that one yet.
but looking at it now.

but i’ve been playing with it in VS Code and i admit you had me stumped for a good 15 minutes.

then i realized you had more than one for loop using i as the iterator.

changing the problem area, to a gives what i think you are seeking.

    for (**a** = 0; **a** < str.length; **a**++) 
    {
        console.log("str.length = "+str.length);
        options[**a**] = str.slice();
        console.log(**a**);
        console.log(str[**a**]);
        
        for (j = 0; j < (factorialize(str.length - 1)); j++) 
        {
            combos[j] = str[**a**];
        }
    }