diff --git a/courses/arrays/manipulate-arrays.md b/courses/arrays/manipulate-arrays.md index 4c15b67..33b0e9c 100644 --- a/courses/arrays/manipulate-arrays.md +++ b/courses/arrays/manipulate-arrays.md @@ -74,5 +74,5 @@ ourArray.unshift("Happy"); `ourArray` القيمة `["Happy"، "J"، "cat"]`.
-نعتذر عن عدم وجود اختبار لهذا الدرس حالياً. نحن نعمل بجد لإعداد اختبارات لجميع الدروس وسنقوم بتوفيرها في أقرب وقت ممكن. +`قم بحذف أول عنصر من المصفوفة myArray وأضف العنصر [Ali", 35"] إلى بداية المصفوفة.`
diff --git a/precodes/arrays/manipulate-arrays.js b/precodes/arrays/manipulate-arrays.js new file mode 100644 index 0000000..0e61098 --- /dev/null +++ b/precodes/arrays/manipulate-arrays.js @@ -0,0 +1 @@ +const myArray = ["a", "b", "c", "d"]; \ No newline at end of file diff --git a/testcases/arrays/manipulate-arrays.js b/testcases/arrays/manipulate-arrays.js new file mode 100644 index 0000000..fd97717 --- /dev/null +++ b/testcases/arrays/manipulate-arrays.js @@ -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!"; +} \ No newline at end of file