Giter VIP home page Giter VIP logo

js-functions-ins-and-outs's Issues

Replace `unlimited` with `arbitrary`

Replace unlimited with arbitrary.

- In Javascript a function can accept an unlimited number of arguments since every function has an arguments object that is a mechanism to handle arguments not in the function definition. 
+ In Javascript a function can accept an arbitrary number of arguments since every function has an arguments object that is a mechanism to handle arguments not in the function definition. 

https://github.com/ga-wdi-boston/js-functions-ins-and-outs#functions-with-1-or-more-arguments

Call back example should be...?

values implies we expect an array as an argument (which we do later on in arrayTransform), recommending changing it to value

Students were really stuck on partial application

Students were really stuck on partial application, even though the code-along was framed as a focus on a function returning another function. Is there another example we could use that doesn't rely on two parameters partially applied? Maybe a static function returned?

Not able to finish with virtual property example.

The memo example is wrong, or I don't understand the intent. Help?

See annotations for questions

const memoFactory = function (memo) {
  let total = 0
  // notice the lack of a local variable here for closure, as well as the lack of a parameter in the
  // below, returned function
  return function () {
    total+= 1
    return total + ": " + memo // where should this be? Is it defined?
  }
}

const memo = memoFactory() // looks like memo isn't defined

 // looks like we're passing an argument to a generated function that names no parameters
const entryMonday = memo("Monday was fun")
const entryTuesday = memo("I liked Tuesday") // ditto
const entryWednesday = memo("Ugh Wednesday") // ditto

console.log(entryMonday) // "1: Monday was fun" // no, what is actually produced is "1: undefined"
console.log(entryTuesday) // "2: I liked Tuesday" // no, what is actually produced is "2: undefined"
console.log(entryWednesday) // "3: Ugh Wednesday" // and so on

Some developers confuse "callback" with "method that takes a callback"

This indicates that sometimes when we receive vague feedback about "understanding callbacks", some developers do not properly have the vocabulary in their mind. A visual diagramming of an example might help (like diagramming a sentence in English).

For example, when a developer says "the reduce callback" what they typically mean is "the reduce method", but what experienced developers would hear is "the function the reduce method receives as the first argument".

That confusion makes it impossible to explain what a callback is until the more experienced developer recognizes the mistake.

[1,2,3].reduce((a, b) => { return a + b; });
//        ^---- referred to as callback, therefor:
//        when we say callbacks are "arguments to functions" they get confused

Honest Lab is too negative. We need a better example.

@jrhorn424 would like us to come up with a more pleasant example than Developers Cheating.

https://github.com/ga-wdi-boston/js-functions-ins-and-outs/blob/master/lib/school_honesty_lab.js

Potential replacement but new ideas welcome, just created on the fly.

'use strict'

// person one
const personOne = {
  name: 'Mike',
  hungry: true,
  food: []
}

// person two
const personTwo = {
  name: 'Bernard',
  hungry: false,
  food: []
}

// people array
const people = [personOne, personTwo]

// function that adds food if person is hungry and makes them not hungry
const eat = function (person) {
  person.food.push("Cake")
  person.hungry = false
}

// function that removes food if person is not hungry and makes them hungry
const digest = function (person) {
  person.food.unshift()
  person.hungry = true
}

// the function should accept an array of developers and two callback functions
const runMealScript = function (arrayPeople, callBackEat, callBackDigest) {
  // loop through the students array and check who is hungry
  for(let i = 0; i < arrayPeople.length; i++){
    // if they are hungry or not 
    // then pass them as an argument to the correct callback 
    if (arrayPeople[i].hungry === true ){
       callBackEat(arrayPeople[i]) 
    } else {
       callBackDigest(arrayPeople[i]) 
    }       
  }
}

// the function should get passed an array of people
// and two callback functions
runMealScript(people, eat, digest)

PVD Thoughts (Did not deliver)

I didn't teach this lesson at all. I felt that what was covered here had already been/will be covered in past/future lessons. I think the only thing that isn't/won't be covered in other lessons is the arguments object but I didn't think that was pertinent enough to warrant having to teach the students in person. I actually didn't know about that myself, so super cool to learn!

That said, we did give this lesson to students and the study as well. We told them to go through these on their own time and informed them that they will have a diagnostic on this Monday morning. I personally don't think they should have a diagnostic on this, but my team disagreed and I was OK with that.

Instead, I delivered this lesson on CSS: https://github.com/ga-wdi-lessons/css-review. It went really well. They were especially impressed with how they can change HTML and CSS with the inspector. I think this is going to set them up well for the DOM lesson.

I also had them do this lesson: https://github.com/ga-wdi-lessons/html-intro on their own prior to the CSS class.

As a preview of next week, we plan to cover layout, DOM and jquery, events and callbacks, scope and context, and es6 features. The plan is to get into APIs and AJAX right after Thanksgiving, but before they start project 1. We will make sure that the team that remains is set up for success on delivering that.

change function syntax

I think setting it up like this will cause great confusion:

const product = function product() {

};

Should be changed to:

const product = function () {
};

README code is double wrong

(per @gaand)
For the reference type arguments demo

// Write a function that takes an array full of integers, doubles each value, and
// returns a new array with those values.
const arrayTimes2 = function arrayTimes2() {
  let result = [];

  for (let i = 0; i < arguments[0].length; i++) {
    result[i] = arguments[0][i] * 2;
  }

  return result;
};

more clear definition of the different types of functions?

const sum = function (first, second) {
  return first + second
}

const sum = (first, second) => {
  return first + second
}

const sum = (first, second) => first + second

const addOne = num => num + 1

Show the different types and talk about the differences

Maintain code in one place

For demos, code should be linked to in the README (either a script or lib), unless that code is intended to be run in a REPL, in which case it is fine as a fenced block. Do not put it in both places.

In a code-along, starter code should be provided on the master branch. Code should be stored in a file on the solution branch, and the consultant can have that branch open while presenting to walk developers through the code-along.

In a lab, starter code should be provided on the master branch. A solution should be provided on the solution branch.

Solution Branch needs to mirror Master

The solution branch README.md needs to mirror the master branch README.md, and needs to include solutions for the master branch code. I now see that there's additional code merged into the solution branch and it intends to include a big section on scope.

Here's an open PR for discussion on the content in the solution branch: #33. While this topic is being discussed, we should have the solution branch contain the solution code that mirrors the current master branch.

Also discussed in this issue, with solution code dump from @jrhorn424: #17

Annotate use of `num` as variable and as parameter

Reference types as arguments

Reference types passed as arguments can be modified within the functions.

Demo - primitive data types as arguments

let num = 1

const change = function (num) {
  num++
  console.log(num)
}

change(num) // 2
console.log(num) // 1

This was causing some confusion as to when num was the global variable and when it was the parameter

Tom's callback explanation

var operation = function(add, num1, num2) {
  var result = add(num1, num2);
  return result;
}

var add = function add(n1, n2) {
  var result = n1 + n2;
  result result;
};

var answer = operation(add, num1, num2);

Code walk through, each step explicitly.

The change to from add to callback confused.

global scope also confusing.

change operation to

function(cb, str1) {
  var result  = cb(str1);
  return result;
}

operation('Hello', Array.protoype.toLowerCase);

Add scope to learning objectives, and add content about scope

A lot of this lesson would make more sense if students had a basic understanding of what scope is. I remember my cohort (009) having a lesson on scope, but it doesn't seem to be included now. I think adding a basic intro to scope in a study or as part of this lesson would be very helpful.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.