I’m trying to convert an angular app from gulp to webpack. in gulp I use gulp-preprocess to replace some variables in the html page (e.g. database name) depending on the NODE_ENV. What is the best way of achieving a similar result with webpack? Answer There are two basic ways to achieve this. DefinePlug…
Author: admin@master
Merge duplicate objects in array of objects
I have below array of objects, I want to merge the duplicate objects based on attribute ‘label’ so that Final output will look like below, Can someone help me identify the approach? Answer I would probably loop through with filter, keeping track of a map of objects I’d seen before, along the…
How do I promisify native XHR?
Want to improve this post? Provide detailed answers to this question, including citations and an explanation of why your answer is correct. Answers without enough detail may be edited or deleted. I want to use (native) promises in my frontend app to perform XHR request but without all the tomfoolery of a mass…
Simple easing function in javascript
I’m having trouble figuring out this simple math problem. I have spent over two hours reading through various related answers on SO and Google, but it seems my high school math knowledge is gone. On the page I have an element, that, once it passes a threshold, gets scaled down, the closer it gets to the…
Why does insertBefore delete the reference node here?
Edit: Found the problem somewhere else, sorry, false alarm! I can’t seem to figure out why insertBefore() is deleting the reference object in this javascript function: The console shows a node being present before insertBefore is executed, but it is somehow deleted and replaced by the new node afterward…
Iterative solution for flattening n-th nested arrays in Javascript
Can anyone show me an iterative solution for the following problem? I solved it recursively but struggled with an iterative solution. (Facebook Technical Interview Question) Solution must work with n-th nested array elements (i.e. it must still work if someone modifies the array values/placement in the exampl…
How to load a script only in IE
I need a particular script to be triggered in Internet Explorer browsers Only! I’ve tried this: Unfortunately this actually stops the script from being loaded. EDIT: For everyone asking why I need this: IE makes scrolling extremely jumpy when using some animations. In order to address this I need to imp…
Google charts from MySQL
I have tried for several hours to get MySQL data in a Google charts but I can’t wrap my head around how to make a working page from the examples I’ve come across on the internet. To start fresh I took a example from Google charts and manually filled it with data. This gives me the graph I want to
Prevent PDF auto download by idm using pdf.js
I’m using PDF.Js to embed PDF file for preview, and I removed the script of download and open files from the viewer.js , but when I test the page and PDF file try to show, the Internet Download Manager download it and abort the preview .. after search I found that using object instead of iframe may solv…
why is this chrome.browserAction.setIcon method not working?
I’m looking at the documentation page and I can’t figure out whats wrong in my code: the documentaion says : Note that ‘details.imageData = foo’ is equivalent to ‘details.imageData = {’19’: foo}’ so I’m extremely confused Answer Your code is basically a bi…