A few notes about things I’ve seen in your code.
const point = (x, y) => {
return { ‘x’: x, ‘y’: x };
};
Properties are not actually evaluated so we can leave the quotation marks off.
const point = (x, y) => {
return { x: x, y: x };
};
Note, you still need quotation marks if the property name isn’t a legal variable name, e.g. if it contains spaces or punctuation.
When we want to make an object with properties named the same as some variables and the values the values of the variables we can leave out the property names altogether.
const point = (x, y) => {
return { x, y };
};
A lot of you wrote something like:
const o = { x: 10, y: 20 }
return o;
But you can put any expression after a return
:
So you can just write this:
return { x: 10, y: 20 }
Similarly, the value positions of an object can be any expression so rather than this:
const x = (p1.x + p2.x) / 2;
const y = (p1.y + p2.y) / 2;
return { x: x, y: y };
You can just write this:
return {
x: (p1.x + p2.x) / 2,
y; (p1.y + p2.y) / 2
};
A lot of you are trying to use search
when you should be using indexOf
.
They do similar things but search
is more powerful. Which means it isn’t always doing what you might think.
const s = ‘foo * bar’;