I'm SO close to solving this problem :D

function modifyMultiply (str,loc,num) {
//   console.log(str)
   const myArray = str.split(' ');
   console.log(myArray)
   console.log(myArray[loc])
  
   const newArray = [];
   for (let i = 0; i < myArray.length; i++) {
     newArray.push(myArray[loc])
   }
  const answer = newArray.join('-')
  console.log(answer)
  return answer;
  }

I get ‘string-string-string-string’ instead of ‘string-string-string-string-string’ lol

ah we want the length of the number right

function modifyMultiply (str,loc,num) {
//   console.log(str)
   const myArray = str.split(' ');
   console.log(myArray)
   console.log(myArray[loc])
  console.log(num)
  
   const newArray = [];
   for (let i = 0; i < num; i++) {
     newArray.push(myArray[loc])
   }
  const answer = newArray.join('-')
  console.log(answer)
  return answer;
  }

boom!

I appreciate y’all’s assistance :smiley:

good job.
And now look at this:

function modifyMultiply(str,i,n) {
  return Array(n).fill(str.split(' ')[i]).join('-');
} 

:rofl: :rofl:
I don’t even understand that lol.

that’s fine. When I was looking at fill() for the first time, that was the same situation lol

lol. any article you can send on the Array part of that?

Well, article about fill itself has such examples.

Maybe you wanna go for article about array itself?

I hope it will be not very confusing: array is an object :upside_down_face:

lol yeah I just don’t get what Array(n) does. How does it know what the array is just by typing Array?

just check it

console.log(new Array(4));

and check this:

console.log(new Array(4).fill(null));

It knows because Array is an object class, which is built-in.

console.log(new Something(4));

this will throw error because I asked some stuff which is not built-in

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.