lundi 21 mai 2018

check my code for improvements in javascript?

https://www.hackerrank.com/challenges/apple-and-orange/problem That is link to problem i am doing plz tell what improvements it needs.thank uu

function countApplesAndOranges(s, t, a, b, apples, oranges) {

// a and b location
var arr3=[];
for(var i=s;i<=t;i++){
    arr3.push(i); } //starting and ending point

//console.log(arr3);
var m=apples.length; // numbers of apples
//console.log(m);
var n=oranges.length; // number of oranges
//console.log(n);
var a,b,x,y,z,app,ora,count1,count2;
var arr1=[];
var arr2=[];
for(x in apples){
    app=a+apples[x];
    arr1.push(app);}
for(y in oranges){
    ora=b+oranges[y];
    arr2.push(ora);}
count1=0;
count2=0;
// console.log(arr1);
//console.log(arr2);
for(z in arr1){
    if(arr3.indexOf(arr1[z])!=-1){
        count1+=1;
    }
    }
for(z in arr2){
    if(arr3.indexOf(arr2[z])!=-1){
        count2+=1;}
    }
console.log(count1+"\n"+count2+"\n");

}




Aucun commentaire:

Enregistrer un commentaire