Home > front end >  Ask for help!
Ask for help!

Time:04-27

These two problems with JS how write ah, feel a little difficult,

1.


Given a includes an array of n integers nums and a target value target, find out the nums equal the sum of the number of target, and print out all the index, index can't repeat the same results,

For example: nums=,5,8,17,29,33,39,11,16 [1], target=33
Results 1:5, 2:3, 8,...



!!!!!!!!!! Use the title of test data, the output results behind the code!!!!!!!!!!





2. Given a set start and end time of the array, to find out in the array cross time and spare time

[2020-03-20, 2020-03-20],
[2020-05-20, 2020-05-20],
[2020-04-20, 2020-04-20],
[2020-08-20, 2020-08-20],
]
Spare time: 2020-03 ~ 23-2020-04-19, 2020-07-23 ~ 2020-07-23,...
Crossed period of time: 2020-05-20 ~ 2020-05-20,...


!!!!!!!!!! Use the title of test data, the output results behind the code!!!!!!!!!!



//code behind, after finish, click save button in the upper left corner, prompt "save success can
"//if you don't save that success, need to put the "name", behind the copy to # and refresh the page

//please make sure the correct code, cannot appear to run an error

CodePudding user response:

50 points, too lazy to get the

CodePudding user response:

reference 1/f, illiterate old gu response:
50 points, too lazy to get the

The younger brother I only 50

CodePudding user response:

reference 1/f, illiterate old gu response:
50 points, too lazy to get the

You wait for me next time supplies

CodePudding user response:

 

<script>
Let nums=[1, 5, 8, 17, 29, 33, 39, 11, 16].
Let target=33;

Var subsets=function (nums) {
Let res=[],
Len=nums. Length;
For (the let I=0; I & lt; (1 & lt; let arr=[];
For (let j=0; J & lt; Len. J++) {
If (I & amp; (1 & lt; }
If (sums (arr)==target) {
Res. Push (returnkey (arr));
}
}
Return res;
};

The function returnkey (arr) {
Let the key=' ';
For (the let I=0; I & lt; Arr. Length; I++) {
Key==' '? Key="" + arr [I] key: key +=", "+ arr [I] key.
}
The return key.
}

The function sums (arr) {
Let the sum=0;
For (the let I=0; I & lt; Arr. Length; I++) {
The sum +=arr [I] value;
}
return sum;
}

Let the result=subsets (nums);
console.log(result);
</script>




Write a

CodePudding user response:

1

 function fun1 (arr, target) {
Var r=[];
for(var i=0; iR=fun2 (arr, target, r, [I]);
}
return r;
}
The function fun2 (arr, target, r, e) {
Var NXT=0;
Var val=0;
Var pos=[];
Var num=[];
For (var I=0; iNXT=nxtPos. Push (e [I])
Val +=arr [I] [e];
Num. Push (arr [e] [I]);
}
If (val==target)
{
R.p ush ({pos: e, num: num, expr: num. Join (' + ') + "==" + target});
}
Else if (val & lt; Target)
{
For (var I=NXT + 1; iVar n=[];
for(var j=0; jNancy (polocy) pelosi ush (e [j])
}
Nancy (polocy) pelosi ush (I)
R=fun2 (arr, target, r, n)
}
}
Return r
}
The console. The log (fun1 (,2,3,4,5,6,7,8 [1], 15));

CodePudding user response:

reference 4 floor Stephen_112 response:
 

<script>
Let nums=[1, 5, 8, 17, 29, 33, 39, 11, 16].
Let target=33;

Var subsets=function (nums) {
Let res=[],
Len=nums. Length;
For (the let I=0; I & lt; (1 & lt; let arr=[];
For (let j=0; J & lt; Len. J++) {
If (I & amp; (1 & lt; }
If (sums (arr)==target) {
Res. Push (returnkey (arr));
}
}
Return res;
};

The function returnkey (arr) {
Let the key=' ';
For (the let I=0; I & lt; Arr. Length; I++) {
Key==' '? Key="" + arr [I] key: key +=", "+ arr [I] key.
}
The return key.
}

The function sums (arr) {
Let the sum=0;
For (the let I=0; I & lt; Arr. Length; I++) {
The sum +=arr [I] value;
}
return sum;
}

Let the result=subsets (nums);
console.log(result);
</script>




Write a


Thank you, gnome male - ", I'll have a good look at

CodePudding user response:

refer to fifth floor illiterate old gu response:
1

 function fun1 (arr, target) {
Var r=[];
for(var i=0; inullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related