Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function ScaleBalancing(strArr) {
- const w1 = JSON.parse(strArr[0])[0];
- const w2 = JSON.parse(strArr[0])[1];
- let weights = JSON.parse(strArr[1]);
- for (let i = 0; i < weights.length; i++) {
- if (w1 + weights[i] === w2 || w2 + weights[i] === w1) {
- return '' + weights[i]; // should return 5 and break out of function right?
- }
- //if this for loop is omitted the function returns 5
- for (let j = i + 1; j < weights.length; j++) {
- if (w1 + weights[i] + weights[j] === w2 ||
- w2 + weights[i] + weights[j] === w1 ||
- w1 + weights[i] === w2 + weights[j] ||
- w2 + weights[i] === w1 + weights[j]) {
- return '' + weights[i] + ',' + weights[j]; //this returns 1,6
- }
- }
- }
- return 'not possible';
- }
- // keep this function call here
- ScaleBalancing(["[6, 1]", "[1, 10, 6, 5]"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement