* fix: convert js algorithms and data structures * fix: revert some blocks back to blockquote * fix: reverted comparison code block to blockquotes * fix: change js to json Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: convert various section to triple backticks * fix: Make the formatting consistent for comparisons
2.1 KiB
2.1 KiB
id, title, challengeType
id | title | challengeType |
---|---|---|
587d7b8a367417b2b2512b4f | Write Concise Object Literal Declarations Using Simple Fields | 1 |
Description
const getMousePosition = (x, y) => ({
x: x,
y: y
});
getMousePosition
is a simple function that returns an object containing two fields.
ES6 provides the syntactic sugar to eliminate the redundancy of having to write x: x
. You can simply write x
once, and it will be converted tox: x
(or something equivalent) under the hood.
Here is the same function from above rewritten to use this new syntax:
const getMousePosition = (x, y) => ({ x, y });
Instructions
Person
object with name
, age
and gender
properties.
Tests
tests:
- text: 'The output is <code>{name: "Zodiac Hasbro", age: 56, gender: "male"}</code>.'
testString: 'assert((() => {const res={name:"Zodiac Hasbro",age:56,gender:"male"}; const person=createPerson("Zodiac Hasbro", 56, "male"); return Object.keys(person).every(k => person[k] === res[k]);})(), ''The output is <code>{name: "Zodiac Hasbro", age: 56, gender: "male"}</code>.'');'
- text: No <code>key:value</code> were used.
testString: getUserInput => assert(!getUserInput('index').match(/:/g), 'No <code>key:value</code> were used.');
Challenge Seed
const createPerson = (name, age, gender) => {
"use strict";
// change code below this line
return {
name: name,
age: age,
gender: gender
};
// change code above this line
};
console.log(createPerson("Zodiac Hasbro", 56, "male")); // returns a proper object
Solution
const createPerson = (name, age, gender) => {
"use strict";
return {
name,
age,
gender
};
};