-
Notifications
You must be signed in to change notification settings - Fork 0
Custom JS Methods
Alexandre Dagenais edited this page Mar 30, 2016
·
5 revisions
#Custom JS Methods ##Array ####_combine() []._combine(_arr,_operator)
Description
add, subtract, multiply or divide the content of 2 arrays
Parameters
| Parameter | Description | optional |
|---|---|---|
| _arr | Array or number to combine with the array. If this is a number it will be applied to every element of the array. If the arrays are not the same length, the smaller array will be filled with 0 or 1 (since you can't divide by 0) | |
| _function | String of the mathematical Operator ("+", "-" , "/" , "*") |
Returns
Array
Example(s)
/* Parameter = Array --------------------------------------------------------------------- */
var arrA = [0,1,2,3,4];
var arrB = [1,1,2,2,0];
//sum
arrA._combine(arrB,"+"); // returns [1,2,4,5,4]
//diff
arrA._combine(arrB,"-"); // returns [-1,0,0,1,4]
//multiply
arrA._combine(arrB,"*"); // returns [0,1,4,6,0]
//divide
arrA._combine(arrB,"/"); // Because of index 4 of arrB, returns an error : Cannot divide by 0
/* Parameter = different length Array ----------------------------------------------------- */
var arrB = [2,2,0];
//_combine will transform [2,2,0] to [2,2,0,0,0]
arrA._combine(arrB,"+"); // returns [2,3,2,3,4]
/* Parameter = Number --------------------------------------------------------------------- */
arrA._combine(3,"+") // returns [3,4,5,6,7]##PropertyGroup ##Property ##FootageItem