I need to pass array and a few variables to a function at the same time.
I have my working code for this task in C:
#include<stdio.h>
void printing(int counter, int a[], int v1, int v2, int v3, int v4) {
// Function goes here
}
int main(){
int i,v1,v2,v3,v4,a[0] = 1;// etc... I declare manually all elements of array a[]
for (i = 0; i < n; i++) {
printing(i, a, v1, v2, v3, v4);
}
return 0;
}
Do you know how this could be translated into javascript?
>Solution :
Welcome to js,
function printing(counter, a, v1, v2, v3, v4) {
// Function goes here
// a is the array
}
var
i = 1,
v1 = 1,
v2 = 1,
v3 = 1,
v4 = 1,
n = 5;
const a=[];
a[0] = 1;// etc... I declare manually all elements of array a[]
for (i = 0; i < n; i++) {
printing(i, a, v1, v2, v3, v4);
}
return 0;
the above is a simple translations also make sure to read some docs on how to initialize variables,arrays,function
have a good day with js!