Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. function ScaleBalancing(strArr) {
  2. const w1 = JSON.parse(strArr[0])[0];
  3. const w2 = JSON.parse(strArr[0])[1];
  4. let weights = JSON.parse(strArr[1]);
  5. for (let i = 0; i < weights.length; i++) {
  6. if (w1 + weights[i] === w2 || w2 + weights[i] === w1) {
  7. return '' + weights[i]; // should return 5 and break out of function right?
  8. }
  9. //if this for loop is omitted the function returns 5
  10. for (let j = i + 1; j < weights.length; j++) {
  11. if (w1 + weights[i] + weights[j] === w2 ||
  12. w2 + weights[i] + weights[j] === w1 ||
  13. w1 + weights[i] === w2 + weights[j] ||
  14. w2 + weights[i] === w1 + weights[j]) {
  15. return '' + weights[i] + ',' + weights[j]; //this returns 1,6
  16. }
  17. }
  18. }
  19. return 'not possible';
  20. }
  21. // keep this function call here
  22. ScaleBalancing(["[6, 1]", "[1, 10, 6, 5]"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement