Uploaded by Yayat Ruhiyat

Data Structures Assignment

advertisement
Assignment Number 1
Create an array that contains ["tomato", "broccoli", "kale", "cabbage", "apple"]
Loop the array to print something like this "tomato is a healthy food, it's definitely worth to eat."
Exclude apple because apple is not a Vegetable.
Assignment Number 2
Given object with enum, now create switch statement to react based on that object.status. The
object!
[
{
"name": "John",
"status": "Positive"
},
{
"name": "Mike",
"status": "Suspect"
}
]
Assignment Number 3
Clear the array from the null element inside it.
/*
* DON'T CHANGE
* */
const data = [];
const randomNumber = Math.floor(Math.random() * 100);
function createArray() {
for (let i = 0; i < randomNumber; i++) {
data.push(createArrayElement())
}
// Recursive
if (data.length == 0) {
createArray();
}
}
function createArrayElement() {
let random = Math.floor(Math.random() * 1000);
return [null, random][Math.floor(Math.random() * 2)]
}
createArray()
/*
* Code Here!
* */
console.log(data);
function clean(data) {
// Code here
}
/*
* DON'T CHANGE
* */
if (process.argv.slice(2)[0] == "test") {
try {
clean(data).forEach(i => {
if (i == null) {
throw new Error("Array still contains null")
}
})
}
catch(err) {
console.error(err.message);
}
}
How to run this file with test
node nama_file test
Download