Skip to content

Instantly share code, notes, and snippets.

@erhanyasar
Last active March 9, 2023 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erhanyasar/bf9bd9a6bbfa66cf3c3c0cfadb5f98bc to your computer and use it in GitHub Desktop.
Save erhanyasar/bf9bd9a6bbfa66cf3c3c0cfadb5f98bc to your computer and use it in GitHub Desktop.
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((object) => {
if (typeof object.budget === "number") sum += object.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