Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple Quiz Solutions
const object = {
'1': 30,
'2': 58
};
function objectToArrConverter (obj) {
if (Object.entries(obj).length === 0)
return [];
else {
let arr = Object.entries(obj);
console.log(arr);
return arr;
}
}
objectToArrConverter (object);
const arr = ["John", "Taylor", "john"];
function removeDuplicates (array) {
let noDuplicate = [];
noDuplicate = array.filter((a, b) => array.indexOf(a) === b);
console.log(noDuplicate);
return noDuplicate;
}
removeDuplicates (arr);
const data = [
{ name: "John", age: 21, budget: 23000 },
{ name: "Steve", age: 32, budget: 40000 },
{ name: "Martin", age: 16, budget: 2700 }
]
function getBudgets (arr) {
let sum = 0;
arr.forEach(x => {
sum += x.budget;
});
console.log(sum);
return sum;
}
getBudgets(data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment