-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADD to manipulate-arrays.md a quiz question
- Loading branch information
1 parent
70afc81
commit f1ba9b8
Showing
3 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const myArray = ["a", "b", "c", "d"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"; | ||
} |