Weaverse - JS Dev Test [L1]
by Leo Huynh
HTML
<h1>Weaverse JS Dev Test (Level 1)</h1>
<p>UNCOMMENT the test you want to run then click Run or Cmd/Ctrl + Enter</p>
<pre id="output">---</pre>
<script>
// Capture console.log output and display in the page
const outputElement = document.getElementById('output');
const originalConsoleLog = console.log;
let output = '';
console.log = function (...args) {
const message = args.map(arg =>
typeof arg === 'object' ? JSON.stringify(arg) : String(arg)
).join(' ');
output += message + '\n';
outputElement.textContent = output;
originalConsoleLog.apply(console, args);
};
</script>
CSS
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 40px auto;
padding: 20px;
background-color: #fff;
}
p {
color: #333;
border-bottom: 2px solid #007bff;
padding-bottom: 10px;
}
#output {
background-color: #1e1e1e;
color: #d4d4d4;
padding: 20px;
border-radius: 5px;
font-family: 'Courier New', monospace;
font-size: 14px;
line-height: 1.6;
overflow-x: auto;
}
JavaScript
// ============================================================
// UNCOMMENT the test you want to run
// ============================================================
// test1();
// test2();
// test3();
// test4();
// test5();
/**
* CHALLENGE 1: Given a string, reverse the entire string
* Example: "Hello world!" should return "!dlrow olleH"
*/
function test1() {
function reverseString(str) {
// ============================================================
// Write your code here
return str;
// ============================================================
}
// Do not change below this line
console.log("Test 1:");
console.log("-----------");
const string = "Hello world!";
console.log(
`The reversed string of "${string}" is "${reverseString(string)}"`,
); // Expected output: "!dlrow olleH"
}
/**
* CHALLENGE 2: Capitalize the first letter of each word in a string
* Example: "hello world from javascript" should return "Hello World From Javascript"
*/
function test2() {
function capitalizeWords(str) {
// ============================================================
// Write your code here
return str;
// ============================================================
}
// Do not change below this line
console.log("Test 2:");
console.log("-----------");
const string = "hello world from javascript";
console.log(
`The capitalized string of "${string}" is "${capitalizeWords(string)}"`,
); // Expected output: "Hello World From Javascript"
}
/**
* CHALLENGE 3: Remove duplicates from an array
* Return an array of only unique elements in their original order
* Example: [1, 2, 3, 5, 1, 5, 9, 1, 2, 8] should return [1, 2, 3, 5, 9, 8]
*/
function test3() {
function removeDuplicate(arr) {
// ============================================================
// Write your code here
return arr;
//...