Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getIndicesOfItemWeights(arr, limit) {
- for (let num in arr) {
- var difference = (limit - arr[num])
- //Check if a sum is possible
- if (arr[num] <= limit && arr.includes(difference)) {
- //Sort index in descending order
- if (arr.indexOf(arr[num]) < arr.indexOf(difference)) {
- return [arr.indexOf(difference), arr.indexOf(arr[num])]
- }
- return [arr.indexOf(arr[num]), arr.indexOf(difference)]
- }
- }
- return []
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement