Skip to content

Instantly share code, notes, and snippets.

@ShivrajRath
Last active June 18, 2019 04:06
Show Gist options
  • Select an option

  • Save ShivrajRath/b9e9957e7cfe1bc87a95c9a4590ff6d8 to your computer and use it in GitHub Desktop.

Select an option

Save ShivrajRath/b9e9957e7cfe1bc87a95c9a4590ff6d8 to your computer and use it in GitHub Desktop.
Code to run quick assertion on your function algorithms
const equalityCheck = function(input1, input2) {
if (typeof input1 !== typeof input2) {
return false;
}
if (input1 === input2) {
return true;
}
if (Array.isArray(input1) && Array.isArray(input2)) {
return input1.reduce((acc, el, index) => acc && el === input2[index], true);
}
return false;
};
const testAlgo = function(expectedOutput, ...algoArgs) {
const output = algo(...algoArgs);
console.assert(
equalityCheck(output, expectedOutput),
`Expected output ${expectedOutput} for ${algoArgs} and found ${output}`
);
};
// testAlgo([0, 1], [1, 8 , 7, 9], 9);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment