Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. function getIndicesOfItemWeights(arr, limit) {
  2. for (let num in arr) {
  3. var difference = (limit - arr[num])
  4. //Check if a sum is possible
  5. if (arr[num] <= limit && arr.includes(difference)) {
  6. //Sort index in descending order
  7. if (arr.indexOf(arr[num]) < arr.indexOf(difference)) {
  8. return [arr.indexOf(difference), arr.indexOf(arr[num])]
  9. }
  10. return [arr.indexOf(arr[num]), arr.indexOf(difference)]
  11. }
  12. }
  13. return []
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement