Last active
May 4, 2017 20:41
-
-
Save jgierer12/9302f743a749c00cfdbb1ce939b6d7e6 to your computer and use it in GitHub Desktop.
Solution to r/DailyProgrammer challenge #313 (https://www.reddit.com/r/dailyprogrammer/comments/68oda5/20170501_challenge_313_easy_subset_sum/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default arr => arr.some(x => arr.includes(-x)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subsetSum from './subset-sum.js'; | |
test('[1, 2, 3] -> false', () => { | |
expect(subsetSum([1, 2, 3])).toBeFalsy(); | |
}); | |
test('[-5, -3, -1, 2, 4, 6] -> false', () => { | |
expect(subsetSum([-5, -3, -1, 2, 4, 6])).toBeFalsy(); | |
}); | |
test('[] -> false', () => { | |
expect(subsetSum([])).toBeFalsy(); | |
}); | |
test('[-1, 1] -> true', () => { | |
expect(subsetSum([-1, 1])).toBeTruthy(); | |
}); | |
test('[-97364, -71561, -69336, 19675, 71561, 97863] -> true', () => { | |
expect(subsetSum([-97364, -71561, -69336, 19675, 71561, 97863])).toBeTruthy(); | |
}); | |
test('[-53974, -39140, -36561, -23935, -15680, 0] -> true', () => { | |
expect(subsetSum([-53974, -39140, -36561, -23935, -15680, 0])).toBeTruthy(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment