remote-code-evaluator
v0.2.0
Published
Api for validation code submitions for `javascript` and `dom`.
Downloads
5
Readme
Remote Code Evaluator
Api for validation code submitions for javascript
and dom
.
Example for validating simple html and css changelles
const htmlChallenge = {
id: '123',
tests: [
{
id : "1",
given: `document.querySelector("p").textContent`,
expected: 'hello',
evaluation: 'lodash.isEqual(given, expected)'
},
{
id : "2",
given: `document.querySelector("p").classList[0]`,
expected: "color-dangoer",
evaluation: 'lodash.includes(given, expected)'
},
{
id : "3",
given: `document.querySelector("p").textContent`,
expected: 'hello',
evaluation: 'lodash.isEqual(given, expected)'
},
]
};
const solution = `<p class="color-danger" id="heading">hello</p>`;
validateDOM(htmlChallenge, solution).then((value) => console.log(JSON.stringify(value, null, 2)))
Example for validating javascript. Good for algorithms validation
const twoNumberSumChallenge = {
id: '234',
functionName: 'twoNumberSum',
validation: `lodash.isEqual(given.sort(), expected.sort())`,
tests: [
{
id: '1',
params: [[3, 5, -4, 8, 11, 1, -1, 6], 10],
expected: [-1, 11],
},
{
id: '2',
params: [[3, 5], 8],
expected: [3, 5],
},
],
}
const twoNumberSumSolution = `
function twoNumberSum(array, targetSum) {
let obj = {};
for (let i = 0; i < array.length; i++) {
const y = targetSum - array[i];
if (obj[y]) return [y, array[i]];
else obj[array[i]] = true;
}
return [];
}
`;
validate(twoNumberSumChallenge, twoNumberSumSolution).then(value => {
console.log(JSON.stringify(value, null, 2));
})