Last active
October 22, 2017 13:39
-
-
Save Constantiner/aea9c6f4e9935722f0315e5773a95933 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const getPairs = (arr, x) => arr.reduce(({pairs, subarray}, element) => ({pairs, | |
| subarray: (subarray.forEach(elem => element + elem === x ? pairs.push([element, elem]) : elem), subarray.slice(1))}), | |
| {pairs: [], subarray: arr.slice(1)}).pairs; | |
| const arr = [ 3, 4, 5, -2, 10, 11, 12, -1, 0, 7, 8 ], | |
| x = 10; | |
| console.log(getPairs(arr, x)); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A sample solution for a simple problem of finding pairs in array of integers which sum is equal to some integer value.