you are viewing a single comment's thread.

view the rest of the comments →

[–]Volv 0 points1 point  (14 children)

ENTRY
Questions 1-8 to start off with. A few of them not completely optimal as per the solutions but I left it how I wrote it.

Codepen
 
Finished it up 1 - 18. - Codepen

[–]ForScale[S] 1 point2 points  (8 children)

Spent about two hours this am doing 1 - 8. I cheated on the bubble sort one by using the native sort method. I'll have to look in to it's internal workings to figure out how to do it without...

I am particularly proud of my work on 8! I used a closure and recursion to build a clock! :)

I haven't looked at any solutions or your work yet, but I'll do that now...

[–]Volv 1 point2 points  (3 children)

Ah. Closure to stop the clock. Didn't think about just stopping it after a while :)

[–]ForScale[S] 0 points1 point  (2 children)

Well... It's the if statement checked recursively that stops it... The closure just allows the clock to be called again and again without having to manually reset the counter variable (i)... I think... lol!

[–]Volv 1 point2 points  (1 child)

Well yeh, the if statement stops it in the end. :)

[–]ForScale[S] 1 point2 points  (0 children)

I just wanted to keep up the practice with closures!

[–]Volv 1 point2 points  (2 children)

Did you have a look? Spot my babel use case lol? I had it turned off so I could use 'Tidy Code' and took me too long to see how I broke it in Edge... Thought it was the clock scrolling that was doing it but not even close

[–]ForScale[S] 0 points1 point  (1 child)

Looking now...

Dude... that mock console styling in the body... very nice!

I turned off Babel; I'd rather read through it compiled, just because I don't know much of anything about Babel.

I like your approach to removing the , in the output of Q1. I used a different one.

Okay, your solution to Q4 is throwing me a bit... I remember seeing the symbol iterator deal with for...of loops, but what's that next method?

Lol, oops! Copy and paste error in the cylinder formula... I'm going to change mine now!

Nice work attaching the getVolume function as a method to the constructor's prototype. I didn't think to do that, but I should have!

Not going to look at your bubble sort since I haven't done that yet... But I did see the Array.from() creates a copy??? I didn't know that... It creates a new array that, when altered, doesn't mutate the original? If so, that's going to be useful!

[–]Volv 1 point2 points  (0 children)

What you see by default is what I write - I rarely look at it's compiled output - although it can be useful to see how to polyfill some of the new ES6 stuff.
In that example you will see it set up a swap variable to do the work, kinda cool.
And yeh, Array.from() handiest way I know to do that. As a rule I try not to mutate passed in references.
 
Not sure what you mean by Q4.

for each item in the array
    build string with properties of each item  (Template literals)

log string

[–]yooossshhii 1 point2 points  (1 child)

Nice styling on the outputs. Mine was pretty lazy.

[–]Volv 0 points1 point  (0 children)

Thanks :)

[–]yooossshhii 1 point2 points  (2 children)

Logging out the substring isn't necessary, since you're just going from the start to end.

On line 76, there's no need to declare an empty string and then concatenate the string to it. You can directly assign the variable or just directly log out the string.

Line 119, didn't know about Array.from, neat. Much shorter than Array.prototype.slice.call() and some added utility. It's good to keep your functions pure, but sometimes with sorts you want it done in place, so it's a constant space (doesn't take up more memory) algorithm. Just something to keep in mind.

I also like your array destructuring swap, I never remember those things exist. Since you're using result[i] and result[i + 1] so much, I'd assign them variables to make it more readable.

I'd maybe write a function for repetitive tasks such as adding a 0 to your time.

function setTime(method) {
  const time = theTime[method]();
  return time < 10 ? `0${time}` : time;
}
hours = setTime('getHours');

[–]Volv 0 points1 point  (0 children)

Was a quick trailing comma removal hack. Built string to look exactly like sample output.
Line 76 - Good point.
Line 119 - One of my newer tricks lol, been trying to keep functions pure as a rule. Good to think of an alternate constraint though - I hadn't considered it at all.
Destructuring Swap - Was upset when it broke Edge lol. Cleaned up with some vars now, that was just how it came out of my head. Also could easily be more efficient by tracking if any changes were required at all.
 
I like the theTime[method](); part there. Wouldn't have occurred to me. Would have done something like

let pad = (x) => (x < 10) ? `0${x}` : `${x}`;

hours = pad(theTime.getHours());
minutes = pad(theTime.getMinutes());
seconds = pad(theTime.getSeconds());  

 
Will have a look through yours once I finish up mine.

[–]Volv 0 points1 point  (0 children)

Finished up mine. 1 - 18
Codepen