Skip to content

Conversation

@naab-c
Copy link

@naab-c naab-c commented Aug 1, 2017

No description provided.

@naab-c naab-c changed the title function 1 sol testing exercise sols Aug 1, 2017
@naab-c naab-c changed the title testing exercise sols intermediate javascript exercise sols Aug 1, 2017

describe("TESTS FOR mergeObjects", function() {
it("two objects", function() {
var obj1 = {name: "Foo", num: 3};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

careful with indentation here

@@ -1,0 +1,48 @@
function replaceWith(entry, replaceChar, withChar) {
if (entry.indexOf(replaceChar) !== -1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! small thing - do you need this outer if statement?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, have taken out the outer if statement.

Copy link
Contributor

@elie elie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great start! Try to finish the lodash exercises and set your indentation to be 2 spaces in your editor

if (num < 0)
return num > end && num < start;
else
return num < end && num > start;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need an else here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. indentation changed to 2 spaces on my editor.
  2. I tried taking off the else statement here, re-ran tests and it causes all 'inRange' tests to fail except: 'should handle negative numbers as well'


if(typeof a[key] === 'object')
helper(a[key]);
else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't need an else return here since our function will end after these lines

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have taken out else statement here. will be checked in the next checkin.

var eKey;
switch(shape) {
case "redT":
clear(ctx, (canvas.width), (canvas.height));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are doing the clear in all cases, you don't need to put that code in the switch. Just do it before the switch statement. Also, you don't need the ( ) around cavas.width and canvas.height.


function restartGame(ctx, width, height) {
function drawSquare(ctx, startx, starty, width, height, color) {
var square = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to make the whole object because you don't really save it and use it later.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the only code you really need here is:

ctx.fillStyle = color;
ctx.fillRect(startx, starty, width, height);

Copy link
Contributor

@tigarcia tigarcia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see your hacker snooze code. Did you have a chance to submit it?

person: {
sayHi: function(){
return "This person's name is " + this.fullName
}.bind(obj)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work because obj won't be defined yet. Here is a work around:

var obj = {
  fullName: "Harry Potter",
  person: {
    sayHi() {
      return `This person's name is ${this.fullName}`;
    }
  }
}
obj.person.sayHi = obj.person.sayHi.bind(obj);

}

function invokeMax(fn, num) {
var count = num;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you count down, you don't even need to copy the variable. Numbers are not reference types.


Function.prototype.bind = function(thisArg, ...oArgs) {
var _this = this;
return function(thisArg) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting thisArg here would break your bind. Because the local thisArg would override the thisArg from the outer fucntion. And the thisArg from the outer function is the one you want to use to bind.

@naab-c
Copy link
Author

naab-c commented Aug 14, 2017

Adding partial hack-snooze working code with login functionality working. Need to refactor code to use variable caching and implement other features.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants