JSFiddle - React, Tailwind, and code Playground
by velmurugansp
JavaScript
let add = function(a){
return [a * a];
}
let testCases=[{
input: 5,
output: [25]
},{
input: 10,
output: [100]
},{
input: 100,
output: [10000]
}
];
let passCount = 0, actual;
testCases.forEach(function(value){
if(Array.isArray(value["input"])){
actual = add(...value["input"]);
}else{
actual = add(value["input"]);
}
if(Array.isArray(value["output"])){
if(JSON.stringify(value["output"]) === JSON.stringify(actual)){
passCount++;
}
}else if(actual == value["output"]){
passCount++;
}
});
console.log(passCount);