1.0.1 • Published 2 years ago
@iswilljr/combinations v1.0.1
COMBINATIONS
Combine a list of Numbers, find and check results
Documentation
EXAMPLE
Combinations
const { combinations } = require("@iswilljr/combinations");
const combination = combinations([1, 2, 3, 4, 5, 6], 2);
console.log(combination.combinations);
// [ [ 1, 2 ], [ 1, 3 ], [ 1, 4 ], [ 1, 5 ], [ 1, 6 ],
// [ 2, 3 ], [ 2, 4 ], [ 2, 5 ], [ 2, 6 ], [ 3, 4 ],
// [ 3, 5 ], [ 3, 6 ], [ 4, 5 ], [ 4, 6 ], [ 5, 6 ] ]
const results = combination.findResult(11);
console.log(results.result); // [ 4, 5 ]
const checked = results.checkResults();
console.log(checked);
// {
// values: [ 5, 6 ],
// v_index: [ 4, 5 ],
// valid: true,
// result: 11,
// expected: 11
// }
Find Results
const { findResult } = require("@iswilljr/combinations");
const results = findResult([1, 2, 3, 4, 5, 6], 3, 16);
console.log(results.result); // 'No results found'
const checked = results.checkResults();
console.log(checked);
// {
// values: 'No results found',
// v_index: 'No results found',
// valid: false,
// result: 'No results found',
// expected: 16
// }
Check results
const { checkResult } = require("@iswilljr/combinations");
const checked = checkResult([1, 2, 3, 4, 5, 6], [4, 5], 11);
console.log(checked);
// {
// values: [ 5, 6 ],
// v_index: [ 4, 5 ],
// valid: true,
// result: 11,
// expected: 11
// }