Tag:i++ class Object no return Confession ace Design wrap
Find your other half.
It is said that good programmers are good at object-oriented programming, but they often can't find the other half. Because you are always limiting yourself to being a programmer and not opening your mind.
It's a community time, and here you should find the other half that has the same values but complements you.
For example: You have a strong programming ability, the valuation of 11 points, if the 20 is divided into the best couple to calculate, you should find a strong design ability, the value of 9 points of the girl.
Then when you meet a design ability for 9 of girls, do not hesitate, bold to confess. Don't think the melon behind is sweeter than the front.
For example: There is an ability array [7,9,11,13,15]
, calculated according to the best combined value for 20来, with only 7+13 and 9+11 of two combinations. The index of the array is 0,13 at the index of the array to 3,9 in the array, and the index of 7 on the array is 1,11 at 2.
So we say the function: pairwise([7,9,11,13,15],20)
The return value should be 0+3+1+2 and, that is, 6.
My Code:
functionpairwise (arr, arg) {if(arr.length===0){ return0; } varIdxarr=[]; Outerloop: for(vari=0;i<arr.length-1;i++){ if(typeofarr[i]== "Number"){ for(varj=i+1;j<arr.length;j++){ if(arr[i]+arr[j]===Arg) {Idxarr.push (i); Idxarr.push (j); Arr.splice (J,1, undefined); ContinueOuterloop; } } } } varSum=idxarr.reduce (function(A, B) {returnA +b;}); returnsum;} Pairwise ([1, 1, 1], 2);
The back of the advanced FCC algorithm is a little bit simpler, more than the previous few good long, the comments are not necessary to add
JS-FCC algorithm-pairwise