Skip to content

Commit

Permalink
Update pair function to include reverse pairs (#2)
Browse files Browse the repository at this point in the history
* Update pair function to include reverse pairs

* Formatting

* Sort reverse pairs

* Formatting

* Formatting

* Simplify pair function

* Simplify pair function

---------

Co-authored-by: Paul Littlewood <paullittlewood@numiko.com>
  • Loading branch information
Elwood-P and pl-numiko authored Jan 25, 2024
1 parent 1aac4b3 commit 19f8d5d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// n choose 2
// Generate all possible pairs from the given array (including reverse pairs)
function pair (array) {
return array.map((v, i) => array.slice(i + 1).map(w => [v, w])).flat()
return array.map((v, i) => array.slice(i + 1).map(w => [[v, w], [w, v]])).flat(2)
}

function calcValue (min, max) {
Expand Down

0 comments on commit 19f8d5d

Please sign in to comment.