These are chat archives for codefellows/sea-b15-javascript

3rd
Jun 2014
Tyler Morgan
@toastynerd
Jun 03 2014 02:34
function checkUnique(inputString) {
  var usedChars = {};
  for(var i = 0; i < inputString.length; i++) {
    if(usedChars[inputString.charAt(i)]) {
      return false;
    }
    usedChars[inputString.charAt(i)] = true;
  }
}
for those of you that didn't get to see the last permutation of the unique character problem
Kevin Stephens
@kevinmstephens
Jun 03 2014 04:21
@ivanoats Hey Ivan, we talked about for loops with i===something and I tried some code and it seems to run just fine. Worthless but nevertheless it runs...
function printNums (num) {

    var i;
    for(i = 0; i===0;){

        console.log(num);
        num--;

        if (num==0){
            i++;
        }
    }

    console.log("DONE");

};
Jeff Adelman
@jeffadelman8
Jun 03 2014 04:42

Wouldn't a while loop be easier?

function printNums (num){
while(num !=== 0){
console.log(num);
num--;
}
}

(how do you do the black background, etc?)
Kevin Stephens
@kevinmstephens
Jun 03 2014 04:44
YES, it would! And it's !== not !===
Robert Talamantez
@Talamantez
Jun 03 2014 04:44
three '''
frame your code with that, i think
Kevin Stephens
@kevinmstephens
Jun 03 2014 04:44
The three ''' never works for me.
Robert Talamantez
@Talamantez
Jun 03 2014 04:45
oh what did you use
Kevin Stephens
@kevinmstephens
Jun 03 2014 04:45
I indented my entire block of code one time away from the left side and it worked
Indented in Sublime then pasted
Robert Talamantez
@Talamantez
Jun 03 2014 04:46
cool - thanks
Jeff Adelman
@jeffadelman8
Jun 03 2014 04:47
function printNums (num){
while(num !=== 0){
console.log(num);
num--;
}
console.log("DONE");
}
hmm...
Kevin Stephens
@kevinmstephens
Jun 03 2014 04:47
!=== isn't correct though
Jeff Adelman
@jeffadelman8
Jun 03 2014 04:47
yes, i know, i'm just trying to get the colored code going
Robert Talamantez
@Talamantez
Jun 03 2014 04:48
function printNums (num){
while(num !== 0){
console.log(num);
num--;
}
console.log("DONE");
}
'''
function printNums (num){
while(num !== 0){
console.log(num);
num--;
}
console.log("DONE");
}
'''
Jeff Adelman
@jeffadelman8
Jun 03 2014 04:48
''' function printNums (num){
while(num !== 0){
console.log(num);
num--;
}
console.log("DONE");
}'''
Kevin Stephens
@kevinmstephens
Jun 03 2014 04:48
You guys can send private messages to test it.
Jeff Adelman
@jeffadelman8
Jun 03 2014 04:48
HA!
Kevin Stephens
@kevinmstephens
Jun 03 2014 04:48
:)
Jeff Adelman
@jeffadelman8
Jun 03 2014 04:49
Cool. we're sending them to you Kevin!
Robert Talamantez
@Talamantez
Jun 03 2014 04:49
be on guard
 function printNums (num){
 while(num !== 0){
 console.log(num);
 num--;
 }
 console.log("DONE");
 }
oh wait, it was the ```, not '''
Kevin Stephens
@kevinmstephens
Jun 03 2014 04:50
oh, nice work
Robert Talamantez
@Talamantez
Jun 03 2014 04:51
did you guys use the arraymatrix initializer to make the 2d array in the hw?
Kevin Stephens
@kevinmstephens
Jun 03 2014 04:52
in chapter 2?
Robert Talamantez
@Talamantez
Jun 03 2014 04:52
ya
Kevin Stephens
@kevinmstephens
Jun 03 2014 04:54
I didn't do that problem but I would use var arr = [][];
Robert Talamantez
@Talamantez
Jun 03 2014 04:55
that's supposed to do the same job right?
Kevin Stephens
@kevinmstephens
Jun 03 2014 04:58
Hmm that didn't work actually.
Robert Talamantez
@Talamantez
Jun 03 2014 05:01
I'm working through it, the array.matrix thing is working so far
Kevin Stephens
@kevinmstephens
Jun 03 2014 05:03

Oh in the past I created an array then pushed arrays into it to get the dimension I needed.

var arr = [];

arr.push([]);

Or use a for loop to push as many arrays as you need into it

Robert Talamantez
@Talamantez
Jun 03 2014 05:05
clever way to handle it
Jeff Adelman
@jeffadelman8
Jun 03 2014 05:07
I think you can create it literally like this too if it's simpler...
var stuff = [[],[],[]];
Robert Talamantez
@Talamantez
Jun 03 2014 05:11
thanks jeff

hmm, something wrong with my add function

function add(week, temp) { this.dataStore[week].push(temp); }

function add(week, temp) { this.dataStore[week].push(temp); }
aight, guess I'll tackle it in the am - thanks for the help
Kevin Stephens
@kevinmstephens
Jun 03 2014 05:14
I'm looking at it
Robert Talamantez
@Talamantez
Jun 03 2014 05:15
oh cool
Kevin Stephens
@kevinmstephens
Jun 03 2014 05:17
It looks like they want you to assume a month is 4 weeks and have an array.length of 4 to be stored in the parent array? Is that what you're getting?
The problem isn't very clear
Robert Talamantez
@Talamantez
Jun 03 2014 05:18
yeah, I've got this so far, and it's outputting an 4 sets of 7, all 0's
Array.matrix = function(numrows, numcols, initial) {
    var arr = [];
    for (var i = 0; i < numrows; i += 1) {
        var columns = [];
        for (var j = 0; j < numcols; j += 1) {
            columns[j] = initial;
        }
        arr[i] = columns;
    }
    return arr;
}

function monthTemps() {
    this.dataStore = Array.matrix(4, 7, 0);
    //this.add = add;
    //this.averageWeek = averageWeek;
}
var julyTemps = new monthTemps();
Stephen Boles
@stephenboles
Jun 03 2014 12:08
"When you get bored, click something. If that doesn't help, then turn off your computer immediately." -Douglas Crockford's website
Ivan Storck
@ivanoats
Jun 03 2014 15:32
Good morning folks!
I’ve got a 10am appt in Wallingford close to home, so I’ll be in around 10:30. I am online until then
and let me know if you have an arrays or lists questions. I’m tempted to do some live coding of my own versions in class.
Robert Talamantez
@Talamantez
Jun 03 2014 15:37
words of wisdom
Hailey L. Petway
@hlpetway
Jun 03 2014 15:40
@ivanoats I'd like to see your version of the 3rd exercise from Chapter 2. As well as the first two from Chapter 4. :smile:
Ivan Storck
@ivanoats
Jun 03 2014 15:41
cool
thanks
Ivan Storck
@ivanoats
Jun 03 2014 16:34
funy article on closures: http://leaky.me/javascript-closures/ (Closures for a 6 year old)
Jeff Adelman
@jeffadelman8
Jun 03 2014 16:37
So this is fun... http://bit.ly/1ku4GcL
Kevin Stephens
@kevinmstephens
Jun 03 2014 16:53
Weak, already made slides and now hear that we can't use them in our pitches
Check them out if yall want
Josh Cunningham
@joshcanhelp
Jun 03 2014 16:54
@hlpetway
// Customers
var People = function (name, gender) {
    this.name = name;
    this.gender = gender;
};

var allPeople = [];
for (var i = 1; i <= 10; i++) {
    allPeople.push(new People('Person ' + i, (i % 2 ? 'male' : 'female')));
}
var weThePeople = new List(allPeople);
console.log(weThePeople.length());
weThePeople.displaySameGender = function (gender) {
    this.front();
    for (var i = 0; i < this.length(); i++) {
        if (this.getElement().gender === gender) {
            console.log(this.getElement().name);
        }
        this.next();
    }
};
weThePeople.displaySameGender('female');
Dale Corns
@dcorns
Jun 03 2014 16:54
@kevenmstephens Yes I am disappointed about that, I thought you did a great job on the slides for your project.
Josh Cunningham
@joshcanhelp
Jun 03 2014 17:15
On a stack, why aren't we removing the data from dataStore? We're just moving around the pointer position. Shouldn't we also unset what we're popping off the stack? Might be my minimal data structure knowledge.
Kevin Stephens
@kevinmstephens
Jun 03 2014 17:17
Seems like all you ever need to do is write to the array and change the pointer. I thought about that when clearing the stack is just moving the pointer to 0. I guess that's the advantage is that there is no longer a need to actually remove an element from the array.
Also I'm not sure but I thought I read once that in JavaScript arrays are actually fixed length but a new array is created every time the array changes size. So deleting an element is maybe a slower process than resetting a pointer. Let me see if I can find some evidence to support that.
Josh Cunningham
@joshcanhelp
Jun 03 2014 17:20
I guess the point is that you don't care what else is in the stack, just what's on top? Seems annoying if I want to see everything in the stack, I have to iterate instead of just grabbing the array.
Kevin Stephens
@kevinmstephens
Jun 03 2014 17:21
If you need to see everything in the stack then you shouldn't be using a stack. :)
Josh Cunningham
@joshcanhelp
Jun 03 2014 17:21
zing!
Kevin Stephens
@kevinmstephens
Jun 03 2014 17:24
Hmm, just from browsing around, pop() is a pretty fast operation. Not sure the advantage of using a pointer instead of popping.
Hailey L. Petway
@hlpetway
Jun 03 2014 17:26
Pop! Pop!
Kevin Stephens
@kevinmstephens
Jun 03 2014 17:26
You mean Pop()! Pop()!
Josh Cunningham
@joshcanhelp
Jun 03 2014 17:30
Magnitude.pop().pop();
Hailey L. Petway
@hlpetway
Jun 03 2014 17:34
Thank you Josh! :clap:
Tyler Morgan
@toastynerd
Jun 03 2014 17:45
Yeah, the guy who wrote the book comes from a statically typed language, where you have to do things like allocate memory for an array on creation and use pointers instead of pop(). The book is also trying to groom you for working with linked lists/trees/graphs where you really have to use a pointer.
Josh Cunningham
@joshcanhelp
Jun 03 2014 17:48
@tylermorgan86 Exercise 2 in Chapter 4 is interesting but it looks like it wants us to implement this: http://en.wikipedia.org/wiki/Shunting-yard_algorithm .... am I overthinking this? Including multi-digit numbers and decimals, this could take me all day!
Hailey L. Petway
@hlpetway
Jun 03 2014 17:50
Examples 1 and 2 from Chapter 4 both feel very left-field to me.
Josh Cunningham
@joshcanhelp
Jun 03 2014 17:53
Exercise 1 is written poorly. You can't figure out where an ending parenthesis is supposed to be, it could be anywhere. I took that to mean find unmatched starting parenthesis. The book could use a once-over from an editor bad
Kyle Warbis
@UWarbs
Jun 03 2014 17:55
edit: *badly
Tyler Morgan
@toastynerd
Jun 03 2014 17:56
lol, yeah it could
sadly, it is the only comprehensive resource on Datastructures/Algorithms in javascript
Hailey L. Petway
@hlpetway
Jun 03 2014 18:00
I proposed that we write one for our next app. We can make it a SPA so it counts right?
Josh Cunningham
@joshcanhelp
Jun 03 2014 18:01
@tylermorgan86 Any thoughts on exercise #2?
Tyler Morgan
@toastynerd
Jun 03 2014 18:03
Yeah, just got done downloading, I didn't bring my physical copy of the book in today. Let me take a look.
I would return the location of the opening paren
essentially, you could push an object containing the location and '(' or ')' onto a stack and make sure the stack has an equal number of the opening of and closing parens
using something like stack.length % 2
then pop off parens until you get the single one by itself
Josh Cunningham
@joshcanhelp
Jun 03 2014 18:07
That's what I did for exercise 1, exercise 2 seems a little ... daunting in terms of how long it will take to write that.
Tyler Morgan
@toastynerd
Jun 03 2014 18:08
ahh #2, I was looking at the wrong one, sorry
Josh Cunningham
@joshcanhelp
Jun 03 2014 18:08
np
Parenthesis, decimals, and multi-digit numbers make that one tough
Tyler Morgan
@toastynerd
Jun 03 2014 18:09
Yeah, it doesn't mention needing to be able to parse complex expressions, so I wouldn't worry about them
something that can do simple 1 + 2 to 1 2 + would be fine
Josh Cunningham
@joshcanhelp
Jun 03 2014 18:11
cool, thank you
Tyler Morgan
@toastynerd
Jun 03 2014 18:12
If have an idea of how to create one that can handle complex expressions it would be a great exercise to run through but you don't need to spend a ton of time on these exercises.
Ivan Storck
@ivanoats
Jun 03 2014 18:13
hey all - if it says to create a “menu system” - you don’t have to worry about console input or a HTML UI - just make a function that does what the exercise asks for - you can assume whatever “menu system” you have calls the function.
Andy Ernst
@AndyCErnst
Jun 03 2014 18:26
For the parens, I had a stack of indexes of the start parens. If an end paren came up and there was nothing on the stack it said where the end paren was missing. If it reached the end of the expression with stuff still in the stack, it used the indexes on the stack to say where unmatched start parens were.
Ivan Storck
@ivanoats
Jun 03 2014 18:50
which is why it’s better to define your own object and methods
Andy Ernst
@AndyCErnst
Jun 03 2014 18:53
After 30 minutes trying to do it the right way, just hard-coding it in took 15 seconds.
Ivan Storck
@ivanoats
Jun 03 2014 18:54
:thumbsup:
regarding pitches today, if you have slides, you can use them. Let’s figure out a system to make it quick, though. If you are on linux and have issues with the projector, or have an old mac, and can’t use AirPlay, send me your slides
Zach
@ZachBowman
Jun 03 2014 19:12
Dude, I just spent an hour trying to get nodejs to do console input. I should have read this first.
Ivan Storck
@ivanoats
Jun 03 2014 21:15
JavaScript Stack vs Queue.pdf
Zach Bryan
@ZBryan
Jun 03 2014 21:19
infor Graphic.jpg
Ivan Storck
@ivanoats
Jun 03 2014 22:29
Ivan’s Library Code Challenge:
Feature:
  As a library owner,
  I want to know what books are in the Library,
  So that I can mange my library

Feature:
  As a library owner,
  I wast to know what books are checked out of the Library,
  So that I can keep tack of my assets

Feature:
  As a customer / patron,
  I want to check out a book,
  So that I can read it.
^^ code should use CommonJS modules (assume a Node or Browserify environment)