|
Raskolnikov2089 posted:So I'm not changing the case of finalArray[y] in: That's right, toUpperCase returns a new string and leaves the old one alone You can read the MDN documentation here: quote:The toUpperCase() method returns the value of the string converted to uppercase. toUpperCase() does not affect the value of the string itself.
|
# ? Apr 1, 2015 01:40 |
|
|
# ? Jun 5, 2024 09:21 |
|
Raskolnikov2089 posted:I'm actually just reassigning what Stuff is pointing to, in this case a new string of letters? Yes, exactly.
|
# ? Apr 1, 2015 01:42 |
|
HappyHippo posted:That's right, toUpperCase returns a new string and leaves the old one alone Note: even if toUpperCase did change Stuff in-place, the array still wouldn't be updated because Stuff points to a copy.
|
# ? Apr 1, 2015 10:56 |
|
KARMA! posted:Note: even if toUpperCase did change Stuff in-place, the array still wouldn't be updated because Stuff points to a copy. Not true JavaScript code:
PHP code:
Wheany fucked around with this message at 11:29 on Apr 1, 2015 |
# ? Apr 1, 2015 11:21 |
|
Wheany posted:Not true That's a different case though. Stuff in your example is still a copy, but it's a copy of a reference to an object and you're modifying a property of the referenced object. Setting Stuff to be equal to a new object won't affect the array it was originally in.
|
# ? Apr 1, 2015 15:41 |
|
Raskolnikov2089 posted:I'm actually just reassigning what Stuff is pointing to, in this case a new string of letters? Strings are immutable so it has to work that way.
|
# ? Apr 1, 2015 16:55 |
|
I really need to spend more time working on strings. Arrays I can zoom around in at this point, but string methods I've barely touched.
|
# ? Apr 1, 2015 17:49 |
|
piratepilates posted:That's a different case though. Stuff in your example is still a copy, but it's a copy of a reference to an object and you're modifying a property of the referenced object. Setting Stuff to be equal to a new object won't affect the array it was originally in. I don't really get your point and how it's relevant in JS context.
|
# ? Apr 1, 2015 19:54 |
|
Is there a good resource on designing/organizing APIs inside a MEAN stack? NodeJS in Action has been kind of dense and meandering. I'm hoping for something a little more succinct.
|
# ? Apr 2, 2015 03:11 |
|
Wheany posted:I don't really get your point and how it's relevant in JS context. They were rightly pointing out that you brought up a completely different circumstance to KARMA!'s good point, which would have made more sense if you introduced it like "This can get tricky if your array contains objects because..." or some such thing
|
# ? Apr 2, 2015 22:26 |
|
Dangerllama posted:Is there a good resource on designing/organizing APIs inside a MEAN stack? NodeJS in Action has been kind of dense and meandering. I'm hoping for something a little more succinct. Not exactly sure what you mean but I've learned a bunch from this article https://scotch.io/tutorials/build-a-restful-api-using-node-and-express-4 and the MEAN book from their site is a nice and concise intro to MEAN dev. I've not found a lot about about API design specifically related to Node/Express but this is a pretty good resource for RESTful API design https://github.com/tlhunter/consumer-centric-api-design
|
# ? Apr 3, 2015 15:24 |
|
Opulent Ceremony posted:They were rightly pointing out that you brought up a completely different circumstance to KARMA!'s good point, which would have made more sense if you introduced it like "This can get tricky if your array contains objects because..." or some such thing Yeah, you're correct and it was me, I was the butt.
|
# ? Apr 3, 2015 15:50 |
|
Does there exist any standalone js library for creating dom elements via a zen coding syntax?JavaScript code:
|
# ? Apr 8, 2015 11:57 |
|
mpaarating posted:Not exactly sure what you mean but I've learned a bunch from this article https://scotch.io/tutorials/build-a-restful-api-using-node-and-express-4 and the MEAN book from their site is a nice and concise intro to MEAN dev. I've not found a lot about about API design specifically related to Node/Express but this is a pretty good resource for RESTful API design https://github.com/tlhunter/consumer-centric-api-design Thanks this is good info. I'm basically having trouble figuring out what data to expose to Angular, and how to logically structure my endpoints. Right now the Express server is basically just a web scraper that grabs third party data and presents it back out as JSON (I was running into CORS issues trying to do this all in Angular). I know structuring an API is a bit philosophical, and the answer is usually "it depends on what you're trying to do with the data." But basically I just don't want to have to read ten chapters on middleware components to solve my problem, which is what "NodeJS in Action" felt like. I just kind of want to finish the project. I think scotch.io might be the right direction for me there. Thanks again.
|
# ? Apr 8, 2015 17:16 |
|
I'm trying to set up a page to automatically refresh after a set period of inactivity. I've used some code off StackExchange, but I'm running into an issue. I can't change the source, but I can use the console. Whenever the page refreshes, the console doesn't bring the script over to the new page to keep it running. Is there any way I can make it come over?
|
# ? Apr 8, 2015 18:08 |
|
22 Eargesplitten posted:I'm trying to set up a page to automatically refresh after a set period of inactivity. I've used some code off StackExchange, but I'm running into an issue. I can't change the source, but I can use the console. Whenever the page refreshes, the console doesn't bring the script over to the new page to keep it running. Is there any way I can make it come over? You mean that you, as a client, want this page to refresh itself every so often in your browser? Have you tried the drinking bird? This is a sort of thing that greasemonkey (firefox) and tampermonkey (chrome) are made to deal with. You can write a script and install it into your browser so that it runs whenever you're at page X. Newf fucked around with this message at 21:39 on Jul 2, 2017 |
# ? Apr 8, 2015 18:37 |
|
Yeah, at work I have a webpage with a frame I need to refresh every couple of minutes. I want to get it to refresh that page on one monitor while I do other work on the other monitor. I probably shouldn't install tampermonkey, as tempting as it is. I can edit the source code, so I'll look into either triggering the refresh button or refreshing the frame. I just don't know much JavaScript, so I'll have to learn it in my downtime. I can read it just fine, but I don't know how to write it.
|
# ? Apr 8, 2015 18:52 |
|
Tampermonkey is just a browser plugin. It's not exactly a security concern, since the JS that you run inside of it is sandboxed inside the browser in the same way that all of the js that you run into in the wild is sandboxed inside the browser. It's about tampering with the display of web content, not tampering with the computer or even the browser, really. If you're not sure about it for work, try playing around with it at home first. A script to reload a page every couple of minutes would go something likeJavaScript code:
|
# ? Apr 8, 2015 19:28 |
|
If you don't want to install Tampermonkey you can create a Chrome extension which injects the js on any URL you want and just load the extension as an unpacked extension in developer mode. Should take 5 minutes to set it up.
|
# ? Apr 8, 2015 19:36 |
|
I need to implement relatively complex dynamic autocomplete for a form using a Solr instance as the data source. Is there a straightforward way to implement this (maybe I should just rely on jquery's autocomplete stuff)?
|
# ? Apr 9, 2015 16:27 |
|
EAT THE EGGS RICOLA posted:I need to implement relatively complex dynamic autocomplete for a form using a Solr instance as the data source. Is there a straightforward way to implement this (maybe I should just rely on jquery's autocomplete stuff)? I'd just use one of the autocomplete libs. Bootstrap has a relatively decent one, I haven't used jQuery's though I'm sure it works mostly fine.
|
# ? Apr 9, 2015 16:50 |
|
EAT THE EGGS RICOLA posted:I need to implement relatively complex dynamic autocomplete for a form using a Solr instance as the data source. Is there a straightforward way to implement this (maybe I should just rely on jquery's autocomplete stuff)? How complex does it need to be? jQuery's autocomplete is decent but I personally hate using jQuery UI because it's so big and not too mobile friendly, especially if you're already using other frameworks like Bootstrap, Handlebars, etc. You can also build your own jQuery UI with only the dependencies you need. Check out their NPM page for more info on how to do that. https://www.npmjs.com/package/jquery-ui
|
# ? Apr 10, 2015 01:05 |
|
So I was screwing around with some old stuff I did in coderbyte, and ran across a simple factorial recursion problem I did awhile agocode:
Lo and behold, the opposite of what I thought was happening, was happening. Instead of 7 * 6 * 5 * 4 *3 * 2 *1 = 362880, it was working it's way up the other way around. i.e. 1 * 2 * 3 * 4 * 5 * 6 * 7 = 362880. Okay, weird. So I did some reading and learned more about stack order, so it started to make some sense. Added to the stack from bottom to top, then the stack returns from top to bottom. code:
1 * 2 * 3 * 4 * 5 * 6 * 7 = 5040 Is that how it worked? Raskolnikov2089 fucked around with this message at 18:37 on Apr 10, 2015 |
# ? Apr 10, 2015 02:43 |
|
Yes. It's called "recursive programming" for a reason - it involves a function calling itself. Every time it does, it has to wait for the new function call to resolve, but that function call might involve calling itself again, and again, ad nauseum. Eventually there are no more recursive calls to make and you reach the base case (unless you're stuck in an infinite loop) and the very latest function call finally gets to return a value to the function that called it, instead of recursing further. The returned value finally allows the previous function to proceed executing and return another value to the function that called it, and so on back up the chain, until the original function call you made finally gets to return a value. There's probably more proper technical jargon that someone could chime in with, but that's the gist of it. I'm curious how you know terms like recursion, base case, and stack without being 100% clear on even a basic example? Edit: Actually your code must be flawed from the start somehow, because 7 factorial is 5,040, not 362,880. http://jsfiddle.net/299ufL5y/1/ Anony Mouse fucked around with this message at 07:03 on Apr 10, 2015 |
# ? Apr 10, 2015 06:23 |
|
I've got a quick question about a custom function I'm trying to write for a Google Drive spreadsheet with Google Apps Script. I need to modify it so a single function call will work over an array of values instead of single cells, so that google drive won't flip out when it gets called a couple of hundred times. Here's the function as it is now: code:
Now is there an easy way to modify this so that if 'criterion' is an array with M elements, and 'data' is an array with N elements, the function will return a M*N 2d array, where the function has been called on every single combination?
|
# ? Apr 10, 2015 13:07 |
|
Rahul posted:I've got a quick question about a custom function I'm trying to write for a Google Drive spreadsheet with Google Apps Script. You just want to recurse the call here if your inputs are arrays. Something like this might work: http://jsfiddle.net/wdwvdzzm/ JavaScript code:
Newf fucked around with this message at 13:36 on Apr 10, 2015 |
# ? Apr 10, 2015 13:34 |
|
Anony Mouse posted:Yes. It's called "recursive programming" for a reason - it involves a function calling itself. Every time it does, it has to wait for the new function call to resolve, but that function call might involve calling itself again, and again, ad nauseum. Eventually there are no more recursive calls to make and you reach the base case (unless you're stuck in an infinite loop) and the very latest function call finally gets to return a value to the function that called it, instead of recursing further. The returned value finally allows the previous function to proceed executing and return another value to the function that called it, and so on back up the chain, until the original function call you made finally gets to return a value. I've used recursion a fair amount and understand how to set it up. Stuff like the base case, termination case, etc I fully grasp. I just don't fully understand the underlying mechanism in the stack. It took me a bit last night to see that what firstFactorial(n-1) was doing was re-calling the function (got that part) so that the new n value could be added to the stack (didn't have this part). So now that I know for sure that's how the stack works for recursive addition or multiplication, what about an operation where the order actually matters? If I was to take the same code, but swap the * out with a / or - operand things seem to go to hell if that is how the stack functions: code:
http://jsfiddle.net/299ufL5y/2/ Raskolnikov2089 fucked around with this message at 15:26 on Apr 10, 2015 |
# ? Apr 10, 2015 15:20 |
|
7 - 6 - 5 - 4 - 3 - 2 - 1 Working bottom to top: 7 - 6 - 5 - 4 - 3 - 1 => 7 - 6 - 5 - 4 - 2 => 7 - 6 - 5 - 2 => 7 - 6 - 3 => 7 - 3 => 4 You're not doing 7-6-5-4-3-2-1, you're doing 7-(6-(5-(4-(3-(2-(1)))))).
|
# ? Apr 10, 2015 15:46 |
|
Raskolnikov2089 posted:I've used recursion a fair amount and understand how to set it up. Stuff like the base case, termination case, etc I fully grasp. I just don't fully understand the underlying mechanism in the stack. It took me a bit last night to see that what firstFactorial(n-1) was doing was re-calling the function (got that part) so that the new n value could be added to the stack (didn't have this part). This code you've posted twice now makes no sense. firstFactorial isn't defined at all, you call factorial(7) in the factorial function itself for some reason, and you're only returning any value in the base case (you find k and log it, but you never return it). I'm guessing you must be writing this from memory or something because as written it's completely broken and would result in an infinite loop of factorial(7) assuming that firstFactorial is defined anywhere at all. Edit: For reference, here's the "correct" version (you should never do this in a language without tail call optimization): code:
HappyHippo fucked around with this message at 16:34 on Apr 10, 2015 |
# ? Apr 10, 2015 16:27 |
|
smithandweb posted:How complex does it need to be? jQuery's autocomplete is decent but I personally hate using jQuery UI because it's so big and not too mobile friendly, especially if you're already using other frameworks like Bootstrap, Handlebars, etc. It's not that bad, but it needs to query across multiple Solr fields and populate multiple form fields once one of the autocomplete options is selected. There's no requirement that this be mobile-accessible (it's an internal application on an airgapped network with no access to the internet) so I guess I'l just go with jQuery.
|
# ? Apr 10, 2015 16:56 |
|
HappyHippo posted:This code you've posted twice now makes no sense. firstFactorial isn't defined at all, you call factorial(7) in the factorial function itself for some reason, and you're only returning any value in the base case (you find k and log it, but you never return it). I'm guessing you must be writing this from memory or something because as written it's completely broken and would result in an infinite loop of factorial(7) assuming that firstFactorial is defined anywhere at all. Eugh. Yeah, sorry, I've created several different versions of factorial() by copying and pasting so that I could look at all the different ways the stack is working. One multiplies, another divides, etc etc. I should have double checked that what I copied here was working code. Right now I have 8 versions going (+ - * / with the position of factorial(n-1) moved around). I fixed what I originally posted. At least for multiplication and addition it all makes sense now. I'm going to have to table n - factorial(n-1) === 4 for now. I get why that's happening but it's still a little crazy to me. Raskolnikov2089 fucked around with this message at 18:45 on Apr 10, 2015 |
# ? Apr 10, 2015 18:30 |
|
It's just the distributive property. http://www.freemathhelp.com/distributive-property.html
|
# ? Apr 10, 2015 19:19 |
|
Raskolnikov2089 posted:Eugh. Yeah, sorry, I've created several different versions of factorial() by copying and pasting so that I could look at all the different ways the stack is working. One multiplies, another divides, etc etc. I should have double checked that what I copied here was working code. Right now I have 8 versions going (+ - * / with the position of factorial(n-1) moved around). I fixed what I originally posted. The stack isn't really relevant to this. Just expand out the definition, putting the result of a function call in parenthesis: code:
code:
|
# ? Apr 10, 2015 20:00 |
|
edit: nm
|
# ? Apr 10, 2015 21:24 |
|
HappyHippo posted:The stack isn't really relevant to this. Just expand out the definition, putting the result of a function call in parenthesis: Knowing how the recursive definition works and knowing how the computer actually physically does the thing are very different. Recursive functions confused the hell out of me when I learned about them (I already had a math degree) because I had no conception of a stack and I didn't know where the 'temp' values were being declared, computed, destroyed etc. Stack frames pile up here until they're actually able to work out the values they've been asked for, and then they pass the value back to the frame below it and 'pop' out of existence. Here's what happens to the stack when you call f(4): code:
|
# ? Apr 10, 2015 23:15 |
|
Be careful to not take the "physical" (?) nature of the stack frame too literally. In JS as in other languages they may disappear where you don't expect due to optimizations. Thinking about scopes is more helpful, IME, and can be reused when reasoning about closures and such.
|
# ? Apr 11, 2015 03:19 |
|
Newf posted:Knowing how the recursive definition works and knowing how the computer actually physically does the thing are very different. Recursive functions confused the hell out of me when I learned about them (I already had a math degree) because I had no conception of a stack and I didn't know where the 'temp' values were being declared, computed, destroyed etc. Yeah, it just seemed to me that that Raskolnikov2089 was looking in the wrong place for the answer to their question. I was pointing out that you don't need to bring in the details of the stack in order to see that its 4-(3-(2-(1))) and not (((4)-3)-2)-1; that's implied by how the function is defined.
|
# ? Apr 11, 2015 17:38 |
|
I'm having a funny issue with a javascript dictionary/hash/object/whatever you call a set of key-value pairs. Here's the JS: code:
code:
Here's a screenshot of the console, with the properties window on the right clearly showing that all the data I want is in there. Not shown in the code is how the layouts object is defined. I've not shown this but basically, it makes an AJAX request to the web server (Flask), which responds with JSON. Edit: I've just realised this is probably something to do with JavaScript being asynchronous, but I've no idea how to solve the problem.
|
# ? Apr 12, 2015 14:30 |
|
ArcticZombie posted:Edit: I've just realised this is probably something to do with JavaScript being asynchronous, but I've no idea how to solve the problem. Well, if something is asynchronous, give it a callback function to call when the asynchronous process completes. JavaScript code:
|
# ? Apr 12, 2015 15:03 |
|
|
# ? Jun 5, 2024 09:21 |
|
Thanks, I solved the problem, but I can't understand why the first log has access to the object but the ones after it don't.
|
# ? Apr 12, 2015 18:19 |