Skip to content

Commit

Permalink
ADD to manipulate-arrays.md a quiz question
Browse files Browse the repository at this point in the history
  • Loading branch information
m7medVision committed Feb 21, 2024
1 parent 70afc81 commit f1ba9b8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion courses/arrays/manipulate-arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ ourArray.unshift("Happy");
`ourArray` القيمة `["Happy"، "J"، "cat"]`.

<div class="quiz">
نعتذر عن عدم وجود اختبار لهذا الدرس حالياً. نحن نعمل بجد لإعداد اختبارات لجميع الدروس وسنقوم بتوفيرها في أقرب وقت ممكن.
`قم بحذف أول عنصر من المصفوفة myArray وأضف العنصر <code>[Ali", 35"]</code> إلى بداية المصفوفة.`
</div>
1 change: 1 addition & 0 deletions precodes/arrays/manipulate-arrays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const myArray = ["a", "b", "c", "d"];
33 changes: 33 additions & 0 deletions testcases/arrays/manipulate-arrays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
function handleCodeRun(code) {
try {
const capturedOutput = [];
const originalConsoleLog = console.log;
console.log = (...args) => {
capturedOutput.push(
args.map((arg) => {
if (typeof arg === "object" && arg !== null) {
return JSON.stringify(arg);
}
return arg.toString();
}).join(" "),
);
originalConsoleLog(...args);
};
if (code) {
eval(code);
}
console.log = originalConsoleLog;
return capturedOutput.join("\n");
} catch (error) {
return `${error}`;
}
}
code += "\nconsole.log(myArray);";
const out = handleCodeRun(code);
if (out === '["b","c","d","Ali",35]') {
isPass = true;
msg = "Pass!";
} else {
isPass = false;
msg = "Fail!";
}

0 comments on commit f1ba9b8

Please sign in to comment.