M
Size: a a a
M
M
M
M
M
M
S
S
M
˸A
func.apply(null, [1,,3])
M
M
S
M
NK
S
'use strict';
//Your solution here
const func = (a, b = 2, c) => `a:${a} | b:${b} | c:${c}`;
//=========================
runTests(func, [
{ params: [1, 1, 1], expected: 'a:1 | b:1 | c:1' },
{ params: [1, undefined, 5], expected: 'a:1 | b:2 | c:5' },
{ params: [9, null, 5], expected: 'a:9 | b:2 | c:5' },
]);
//=========== test stuff
function runTests(func, testCases) {
const results = testCases.map((t) => runTest(func, t.params, t.expected));
if (results.some((r) => !r)) {
console.log('TESTS FAILED!');
} else {
console.log('TESTS PASSED!');
}
}
function runTest(func, params, expected) {
const result = func.call(null, ...params);
console.log(
`running test for function ${func.name} with params ${params}. Result = ${result}. Expected = ${expected}`
);
if (result === expected) {
return true;
}
return false;
}
M