Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Javascript passing array elements and variables to function at the same time

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading