Advertisement
hnOsmium0001

bad balancer code js

Dec 11th, 2019
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. const out = document.getElementById('out');
  2.  
  3. const arr = [1, 4, 2, 5];
  4. function sovle(arr) {
  5. const sum = arr.reduce((v, i) => v + i);
  6. precondition:
  7. if(sum % 2 === 1) {
  8. if(arr % 2 === 0) {
  9. return null;
  10. }
  11. for(let i = 0; i < arr.length; ++i) {
  12. if(arr[i] % 2 === 1) {
  13. arr.splice(i, 1);
  14. break precondition;
  15. }
  16. }
  17. return null;
  18. }
  19.  
  20. const halfSum = sum / 2;
  21. const left = [];
  22. const right = [];
  23. for(let i = 0; i < arr.length; ++i) {
  24. for(let j = 0; j < arr.length; ++j) {
  25. if(i === j) {
  26. continue;
  27. }
  28.  
  29.  
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement