RosettaCodeData/Task/Element-wise-operations/AutoHotkey/element-wise-operations-1.ahk

17 lines
521 B
AutoHotkey

ElementWise(M, operation, Val){
A := Obj_Copy(M),
for r, obj in A
for c, v in obj {
V := IsObject(Val) ? Val[r, c] : Val
switch, operation {
case "+": A[r, c] := A[r, c] + V
case "-": A[r, c] := A[r, c] - V
case "*": A[r, c] := A[r, c] * V
case "/": A[r, c] := A[r, c] / V
case "Mod": A[r, c] := Mod(A[r, c], V)
case "^": A[r, c] := A[r, c] ** V
}
}
return A
}