Multiply an array with a number

I need to multiply a float array with a float value without looping over every item. I checked internet a bit and tried some stuff. array.map(number); looks okay to me but Im getting an error:
cannot invoke map(float) on the array type float[]
looks like i need another array to multiply it with but I dont want to loop to create another array.

im beginner to processing.js any possible solution is appreciated

edit: just checked it doesnt let me multiply(scale) float[] with float[] neither. I dont know what to do

1 Like

Hi Sayochi,

Are you trying to do it in processing.js?
Try the following example:

var numbers = [1, 4, 9];
var doubles = numbers.map(function(num) {
  return num * 2;
}); 
// doubles é agora [2, 8, 18]. numbers ainda é [1, 4, 9]

Just apply it to your case.

Best regards

1 Like