lang
stringclasses
4 values
desc
stringlengths
2
8.98k
code
stringlengths
7
36.2k
title
stringlengths
12
162
JS
I am trying to figure out the following regex expression and why it is giving me the result I am getting.I have the following javascript : I would have expected result to have the value of 7777 but instead it has a value of 77977.I was hoping someone could explain why I am getting a value of 77977 and what I would need...
let result = '7979797'.replace ( /797/g , '77 ' ) ;
Need to understand why the regex is not replacing all matches
JS
Javascript : Output : Should I just use string.replace ( ' ( ' , `` ) .replace ( ' ) ' , `` ) .replace ( /\s/g , `` ) ; or RegEx ?
var string = ' ( 37.961523 , -79.40918 ) ' ; //remove brackets : replace or regex ? + remove whitespacesarray = string.split ( ' , ' ) ; var split_1 = array [ 0 ] ; var split_2 = array [ 1 ] ; var split_1 = '37.961523 ' ; var split_2 = '-79.40918 ' ;
How do I split this string with JavaScript ?
JS
I have a javascript countdown script , and I want my page to refresh for once when countdown ends.Here is my full code.This is the code I want to use for refresh : If I add this refreshing code in this part of code below , refresh works.However , this way refresh works every second after countdown ends . But I want it ...
//JavaScript code for countdownfunction getTimeRemaining ( endtime ) { var t = Date.parse ( endtime ) - Date.now ( ) ; var seconds = Math.floor ( ( t / 1000 ) % 60 ) ; var minutes = Math.floor ( ( t / 1000 / 60 ) % 60 ) ; var hours = Math.floor ( ( t / ( 1000 * 60 * 60 ) ) % 24 ) ; var days = Math.floor ( t / ( 1000 * ...
Refreshing page when countdown ends
JS
Most folks look to get script evaluation working . I don't.I 'm trying to place a video as a background ( HTML 5 , not Flash ) and because I have no control over what 's included on the requested pages ( Tumblr - you can have unique code for Index pages and Permalink pages only , you ca n't have a home page , old posts...
{ block : IndexPage } var productElement = document.getElementById ( `` dreamscene '' ) ; if ( productElement == null ) { $ ( `` body '' ) .append ( ' < img src= '' http : //static.tumblr.com/opbsaiu/mqllkvs1c/overlayyyy.png '' style= '' position : fixed ; z-index : -1 ; top : 0pt ; left : 0pt ; width : 100 % ; height ...
How does one ask jQuery to cease script evaluation of AJAX responses ?
JS
I have two Facets I 'm using for filtering via Azure Search : Revit 's 2014 and Revit 2016 but both behave differently in the query.Error 400 ( Bad Request ) when a query with `` Revit 's '' is passed : However the query containing `` Revit '' ( no apostrophe ) works perfectly fine : Azure Search documentation states t...
( search.in ( Application , '7946ca7e-78d0-441a-b939-711cae340dc0||Revit\'s||2014 ' , ' < ^ > ' ) ) ( search.in ( Application , 'c691dc7f-1c08-4a1c-bc4b-db62b214a0b3||Revit||2016 ' , ' < ^ > ' ) ) `` Invalid expression : ' ) ' or ' , ' expected at position 125 in 'ContextId eq '72adad30-c07c-465d-a1fe-2f2dfac950a4 ' an...
Azure Search Query causes a bad response 400 when it contains an apostrophe
JS
In JavaScript , native functions can be identified when coerced to string , for example : However , any function can overload toString ( ) and pretend to be native : I was looking through the source code of Zone.js and found this bit , which does exactly that ( and by design , according to one of the tests ) : Now , I ...
console.log ( document.getElementById ) ; // prints `` function getElementById ( ) { [ native code ] } '' function sum ( a , b ) { return a + b ; } console.log ( sum ) ; // prints `` function sum ( a , b ) { return a + b ; } '' sum.toString = function ( ) { return 'function sum ( ) { [ native code ] } ' ; } ; console.l...
Is there any reason a function would pretend to be native ?
JS
I 've been learning new features of React 16.8 . I believe React 's Pure Component should automatically avoid unnecessary re-render operations.In the following example , the App itself is a stateless component . I use useState to maintain two state objects text and nested : { text } .There are 3 tests . The first 2 tes...
class Headline extends React.PureComponent { render ( ) { const { text } = this.props ; return < h1 > { text } ( render time : { Date.now ( ) } ) < /h1 > ; } } const simpleText = 'hello world'const App = ( ) = > { const [ text , setText ] = React.useState ( simpleText ) const [ nested , setNested ] = React.useState ( {...
How to avoid unnecessary re-rendering of React Component
JS
Say I have two string variables : How do I use regex ( or whatever else is fastest ) to combine a + b to make : In my case , both strings are 4 characters long , always , and the second string is not a fixed character , I just made it a dot to make it look clearer on screen .
a = 'LOVE ' ; b = ' ... . ' ; c = ' L.O.V.E . ' ;
Regex two string variables
JS
I 'm working on a Cordova hybrid app and currently facing issues on Windows 8.1 with Sencha Touch 2 . I got a some divs on a listitem with some subelements . I defined a tap listener . This works fine with Android and IOS , but this does n't work on Win8.1 with Internet Explorer . I 'm always getting the above lying li...
Ext.define ( 'App.view.MyDataView ' , { xtype : 'mydataview ' , extend : Ext.dataview.List , config : { inline : false , title : `` myTitle '' , scrollToTopOnRefresh : false , cls : 'MyDataView ' , itemCls : 'MyDataViewItem ' , pressedCls : 'MyDataViewItemPressed ' , grouped : true , listeners : { tap : { element : 'el...
Sencha Touch 2 : itemtap on IE not targeting divs
JS
I have the following markup.I am unable to change or physically add into this markup , so hence trying to manipulate with jQuery.What I want to achieve from this is to be able to change the word Black to Purple . But only the word Black that appears after the H6 containing `` Colour '' I have this so far : This however...
< h6 > Brand < /h6 > < ul > < li > Orange < /li > < li > Black < /li > < li > Green < /li > < /ul > < h6 > Colour < /h6 > < ul > < li > Green < /li > < li > Blue < /li > < li > Black < /li > < li > Orange < /li > < /ul > $ ( `` h6 : contains ( 'Colour ' ) : .jqueryCheck : contains ( 'Black ' ) '' ) .html ( `` Purple ''...
Finding specific elements with jQuery
JS
The following throws up an alert box reading : 211466719468855300 . Why is this happening , even when I try casting it to a String ? How can I read it accurately ? HTML : JS : Fiddle : http : //jsfiddle.net/zUbym/1/​
< a class= '' delete-link '' data-id= '' 211466719468855298 '' > Delete < /a > ​ $ ( '.delete-link ' ) .click ( function ( e ) { var $ item = $ ( this ) ; var itemID = String ( $ item.data ( 'id ' ) ) ; alert ( itemID ) ; } ) ;
Stop Javascript from rounding big numerical IDs
JS
I 'm developing a reward system for our VLE which uses three separate technologies - JavaScript for most of the client-side/display processing , PHP to communicate with the database and MySQL for the database itself.I 've attached three screenshots of my `` transactions '' table . Its structure , a few example records ...
var Points = { `` Recipient_ID '' : `` 0 '' , `` Points '' : `` 0 '' } ; function getPoints ( data ) { for ( var i = 0 ; i < data.length ; i++ ) { if ( Points [ data [ i ] .Recipient_ID ] ) { Points [ data [ i ] .Recipient_ID ] = parseInt ( Points [ data [ i ] .Recipient_ID ] ) + parseInt ( data [ i ] .Points ) ; } els...
Optimising Database Structure
JS
I 'm trying to teach myself recursion by doing a range function recursively . I ca n't understand why the code below is n't working ? Iterative version : Recursive version :
function rangeList ( num , num2 ) { var arr = [ ] ; for ( var i = num ; i < num2 ; i++ ) { arr.push ( i ) ; } return arr ; } function rangeRecursive ( num , num2 ) { return ( num2 > num ) ? rangeRecursive ( num2 - 1 ) .concat ( num2 ) : [ ] } console.log ( rangeList ( 1 , 7 ) ) ; // returns [ 1 , 2 , 3 , 4 , 5 , 6 ] co...
recursive range function not working
JS
EDIT : It is working with this code : And the code to make the class active : This is working now , but when i 'm going to Site/Projects/Project1 It makes nothing active . And when i go to Site/Projects it makes the projects tab active.So it is working , but i also want the projects tab to stay active when i 'm on Site...
< div id= '' navigation '' > < ul class= '' menu '' > < li > < a href= '' /index.php '' > Home < /a > < /li > < li > < a href= '' /about '' > About Me < /a > < /li > < li > < a href= '' /blog '' > Blog < /a > < /li > < li > < a href= '' /projects '' > Projects < /a > < /li > < li > < a href= '' /contact '' > Contact < ...
change menu color item when active
JS
I have a quick question regarding scope values and assignment in AngularJS . This will probably sound a bit silly , but I 'm curious about it.Assuming I am using controllerAs syntax , and my controller instance is ctrl , I have say , something , like a form with an input like this : Why can I do this in my controller :...
< form name= '' ctrl.form '' > < input type= '' text '' ng-model= '' ctrl.firstName '' / > < /form > if ( this.form. $ valid ) { //code ... } var form = this.form ; if ( form. $ valid ) { //code }
$ scope values in AngularJS
JS
I have the book Jquery in Action , and it mentions these three functions when talking about removing conflict with other libraries . However , I do n't know what the difference is between them and do not understand the book 's explanation.Does anyone know what the difference is ? Thanks .
jQuery ( function ( $ ) { alert ( ' I '' m ready ! ' ) ; } ) ; var $ = 'Hi ! ' ; jQuery ( function ( ) { alert ( ' $ = ' + $ ) ; } ) ; var $ = 'Hi ! ' ; jQuery ( function ( $ ) { alert ( ' $ = ' + $ ) ; } ) ;
What is the difference between these functions ?
JS
So pretty much I 'm making a little web app to get better with using the canvas , but I 'm stuck . I would like a rotating n-sided polygon ( the drawing of lines already works ) . The game loop loops through a grid array ( each point on the grid holds a subclass of a Point ( ) object ) , and calls the tick ( ) method o...
// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # // THIS IS THE PROBLEM CLASS.// So pretty much , when the game loop calls the tick ( ) funciton// of ANY ShapePoint object , everything hangs . The game is still// looping through the ENTIR...
This is an infinite loop , but I can not for the life of me figure out why
JS
I 'm reading Ionic 's source code . I came across this regex , and i '' m pretty baffled by it . Ok , it 's grouping on every char that is either a white space , or non white space ? ? ? Why did n't they just doAm I missing something ?
( [ \s\S ] + ? ) ( .+ ? )
What 's the difference between these regexes
JS
Using regular expression , I want to select only the words which : are alphanumericdo not contain only numbersdo not contain only alphabetshave unique numbers ( 1 or more ) I am not really good with the regex but so far , I have tried [ ^\d\s ] * ( \d+ ) ( ? ! . *\1 ) which takes me nowhere close to the desired output ...
I would like abc123 to match but not 123.ab12s should also matchOnly number-words like 1234 should not matchWords containing same numbers like ab22s should not match234 should not matchhel1lo2haha3hoho4hel1lo2haha3hoho3 abc123ab12shel1lo2haha3hoho4
Match the alphanumeric words ( NOT NUMERIC-ONLY words ) which have unique digits
JS
Why are some JavaScripts encapsulated within these tags :
< ! -- // -- > < ! [ CDATA [ // > < ! -- some js here// -- > < ! ] ] >
Why are javascripts sometimes surrounded by these tags ?
JS
I have just started learning Angular2 , and was wondering why the developers decided to use various different wrapper in he html ? For instance : I 'm sure there is a nice logical reason behind it , and I am aware that they 're used for differing purposes , but at first glance it seems inconsistent and an unnecessary o...
[ ( ngModel ) ] = '' some.property '' ( click ) = '' someMethod ( ) '' [ src ] = '' some.property ''
Why was the design decision taken to use differing brackets ?
JS
I have the following js fiddle : https : //jsfiddle.net/0c208z9e/Essentially I want to apply the translation , but undo the rotation from this : This is the css that gets applied to the text that I want facing the user at all times ( spherically billboarded ) I want the text to be billboarded ( ie . always facing the u...
@ keyframes rotate { 0 % { transform : rotateX ( 0 ) rotateY ( 0 ) rotateZ ( 0 ) ; } 100 % { transform : rotateX ( 360deg ) rotateY ( 360deg ) rotateZ ( 360deg ) ; } } .inset { margin-top : 40 % ; margin-left : 40 % ; transform : translateZ ( 120px ) ; color : grey ; } .inset : hover { color : white ; } .outset { margi...
Billboarding text with css
JS
I am using validated methods ( mdg : validated-method ) with LoggedInMixin ( tunifight : loggedin-mixin ) .Now I have a problem with my unit tests , as they fail with notLogged error , because in the unit tests there is no logged user of course.How do I have to stub that ? methodunit testUnit tests throws Error : [ not...
const resetEdit = new ValidatedMethod ( { name : 'reset ' , mixins : [ LoggedInMixin ] , checkLoggedInError : { error : 'notLogged ' } , // < - throws error if user is not logged in validate : null , run ( { id } ) { // ... } } ) describe ( 'resetEdit ' , ( ) = > { it ( 'should reset data ' , ( done ) = > { resetEdit.c...
MeteorJS : How to stub validated method in unit test
JS
Edit Sorry my question was a bit unclear . I want to enforce that the getList Parameter is always required . So I do n't have a default value for it . e.g I want the user always to supply a getlistI 'm trying to create a constuctor with some optional parameters and some requiredWhen I do this I 'm getting an error getL...
export class PageConfig { constructor ( { isSliding = false , } : { isSliding ? : boolean getList : ( pagingInfo : PagingInfo ) = > Observable < any > } = { } ) { } } class UsersPage { config = new pageConfig ( { this.getList } ) getList ( pagingInfo : PagingInfo ) { // do work ... } }
Typescript destructuring with required parameter
JS
I have an array with some duplicates . An efficient algorithm for sorting the array based on the duplicate count e.g . Because the counts are as followings [ 3 , 2 , 2 , 1 , 1 ] I came up with : Which is about Θ ( 3 N + N log N ) ? Perhaps something faster with lodash ? Maybe keep a sorted priority queue as I do the co...
[ 'd @ me.com ' , ' z @ gmail.com ' , ' e @ me.com ' , ' b @ me.com ' , ' c @ me.com ' , ' z @ gmail.com ' , ' z @ gmail.com ' , ' b @ me.com ' , ' e @ me.com ' ] = > [ ' z @ gmail.com ' , ' e @ me.com ' , ' b @ me.com ' , 'd @ me.com ' , ' c @ me.com ' ] const itemCounts = { } const ordereditems = [ ] for ( let i = 0 ...
Order array of email addresses by frequency counts
JS
I found a javascript that deals with HTML5 File Reader API . It 's written in pure javascript , I am in the process of converting it to a jQuery script . But am getting stuck at this point.This works : This fails : What is a solution to this problem ?
document.getElementById ( 'drop-area ' ) .addEventListener ( 'drop ' , function ( e ) { e.preventDefault ( ) ; e.stopPropagation ( ) ; console.log ( e.dataTransfer.files ) ; // outputs the right stuff } , false ) ; $ ( ' # drop-area ' ) .on ( 'drop ' , function ( e ) { e.preventDefault ( ) ; e.stopPropagation ( ) ; con...
Why does this plain JavaScript work and it 's equivalent jQuery fails ?
JS
If orderBook.no is same then I have to place that only once and add a tr within the tdI get a table like this But I need a table like Onclick the plus button i need to display thewith single update button per row . I have implemented like ng-click is not working . i have included a index like for first time a no comes ...
< tr ng-model= '' check '' ng-repeat= '' orderBook in orderBookDetails| orderBy : 'orderBook.no ' '' value='check= $ scope.orderBookDetails.sowNo ' > < td ng-if='check ! =orderBook.no ' > { { orderBook.no } } < /td > < td > { { orderBook.location } } < /td > < td > { { orderBook.finYr } } < /td > < td ng-if='orderBook....
I want to display the table row as inner table row if the first field is same how to perform this
JS
I have many html tags with class = 'class1 ' . They all happen to be/ and always will be the same type of element . For example input elements.Is there a performance difference betweenand Thanks ! NOTE : In this case i need information specifically pertaining to IE8 , however a mention of a cross browser solution is im...
$ ( `` input.class1 '' ) $ ( `` .class1 '' )
Jquery selector , should I specify type of html tag ?
JS
This one says false , meaning the `` '' is a number : This one says NaN , meaning the `` '' is not a number and can not be converted : I was expecting the second code to convert `` '' to 0 since `` '' is a number when tested in IsNaN but I was wrong ! Am I getting crazy or I just missed something ?
alert ( isNaN ( `` '' ) ) ; alert ( parseFloat ( `` '' ) ) ;
What is `` '' in JavaScript really ?
JS
How do I know what traverses the DOM and what does n't ? It seems like this returns all the div elements AND THEN does another scan for P elements on each dom element that was returned in the first div search.The class ones do n't seem to scan the dom . They only filter the previous list $ ( 'div ' ) for elements that ...
$ ( 'div p ' ) $ ( 'div .foo ' ) $ ( 'div , div ' )
Some questions about how jquery selectors traverse the dom
JS
I know you can use the : wheninitializing objectsusing a ternary operatorusing labelsOpening my console in a Chrome browser I can execute : That works fine . Then I type the same but using a colon instead : Why does using a : still work and execute the open function ?
window.open ( 'http : //google.ie ' ) window : open ( 'http : //google.ie ' )
Why does colon notation work in place of a dot when executing a function ?
JS
I am creating a contact form for my website and and using javascript to the first layer of validation before submitting it which is then checked again via php but i am relatively new to javascript , here is my script ... How can i write this more efficiently and make the alert show if all the fields are filled out , th...
$ ( `` # send '' ) .click ( function ( ) { var fullname = $ ( `` input # fullname '' ) .val ( ) ; var email = $ ( `` input # email '' ) .val ( ) ; var subject = $ ( `` input # subject '' ) .val ( ) ; var message = $ ( `` textarea # message '' ) .val ( ) ; if ( fullname == `` '' ) { $ ( `` input # fullname '' ) .css ( `...
More efficient way of writing this javascript
JS
I was checking out node.green and under destructuring , assignment > nested rest , the following example function is used : Now , I understand destructuring but I can not figure out why how a was rewritten to [ 1 , 2 , 2 ] Also [ ... [ a [ 2 ] , last ] ] = a ; returns [ 1 , 2 , 1 ]
function f ( ) { var a = [ 1 , 2 , 3 ] , first , last ; [ first , ... [ a [ 2 ] , last ] ] = a ; return first === 1 & & last === 3 & & ( a + `` '' ) === `` 1,2,2 '' ; } console.log ( f ( ) )
ES2015+ Nested Rest explanation
JS
Function scoping offers the only privacy in JavaScript.So the canonical : ... is problematic in that it offers no encapsulation for the injected dependencies.An alternative ( albeit slightly different in terms of location of foo ) that offers real encapsulation might be : But I rarely see this pattern . Is there a good...
function Ctor ( dep1 , dep2 ) { this._dep1 = dep1 ; this._dep2 = dep2 ; } Ctor.prototype.foo = function ( ) { // use this._dep1/2 ... } function factory ( dep1 , dep2 ) { return { foo : partial ( foo , dep1 , dep2 ) , // or use bind ( partial could be a library fn for partial application ) } ; } function foo ( dep1 , d...
Privacy in JavaScript
JS
Scenario : Displaying the expansion panel name and content Dynamically using Angular material expansion panel using JSON.Issue : I able to place the Panel name Dynamically but for the content , I need to check the JSON in that I have a type key so based on type I need to push that particular functionality that particul...
[ { module : `` Person Details '' , type : 'table ' , moduleData : [ { `` firstName '' : '' MaxRunner '' , `` ID '' : '' 12345 '' , } ] } , { module : `` Current Location '' , type : 'horizontal-stepper ' , CurrentData : [ { `` step '' :1 , `` description '' : '' Philips '' , `` status '' : true } , { `` step '' :2 , `...
How to dynamically get the values from Object Type and implement in Expansion panel Angular material ?
JS
Why ca n't whereAmI ( ) access privateSomething ? and how do i place whereAmI ( ) in the same context as addFunc ( ) ?
( function ( ) { var privateSomething = `` Boom ! `` ; var fn = function ( ) { } fn.addFunc = function ( obj ) { alert ( 'Yeah i can do this : '+privateSomething ) ; for ( var i in obj ) fn [ i ] = obj [ i ] ; } window.fn=fn ; } ) ( ) ; fn.addFunc ( { whereAmI : function ( ) { alert ( 'Nope I\ 'll get an error here : '...
Javascript Scope in Injected Function
JS
I am trying to add a new transition while a transition is running with a condition that if bar1 width matches bar2 then the bars change positions . I have used transition ( ) .tween to see if the condition is met . When the 2nd transition starts , the 1st stops . I want the 1st transition to continue running until the ...
window.i1 = 0 ; window.i2 = 0 ; var svg = d3.select ( `` body '' ) .append ( `` svg '' ) .attr ( `` width '' , 500 ) .attr ( `` height '' , 500 ) ; var bar1 = svg.append ( `` rect '' ) .attr ( `` fill '' , `` green '' ) .attr ( `` x '' , 20 ) .attr ( `` y '' , 40 ) .attr ( `` height '' , 20 ) .attr ( `` width '' , 40 )...
Add a concurrent transition during another transition if a condition is met
JS
I use a template that generates a Bootstrap tab layout . Like below : Now this is pretty simple and straightforward tab navigation that can be hardcoded and achieved.I have a dynamic ng-repeat on the ul 's li and the tab-content 's divs.The JSON that I get from the REST service is something that contains the data for t...
< div class= '' a '' > < ul class= '' nav nav-bar nav-stacked '' role= '' tabs '' > < li > < a href= '' # home '' > < /a > < /li > ... < /ul > < div class= '' tab-content '' > < div id= '' home '' > abc < /div > ... < /div > < /div > { `` 0 '' : `` a '' : [ { // a- tab data `` 0 '' : `` abc '' , // abc - data to be dis...
AngularJS : Is there a better way to achieve this than the one specified ?
JS
I 'm using data attributes in HTML elementsExample : In jQuery I 'm getting the data attribute using $ ( this ) .data ( `` color '' ) and adding it has a class name to the element.Is it necessary to validate first if a data attribute exists before adding it as a class ? Example : or does jQuery handle that ? I tried ru...
< div class= '' fruit '' data-color= '' red '' > ... < /div > // $ ( this ) is .fruit divif ( $ ( this ) .data ( `` color '' ) ) { $ ( this ) .addClass ( $ ( this ) .data ( `` color '' ) ) ; //adds data value as class to element }
Is it necessary to check if element has attribute ?
JS
I 'm working with bootstrap-select and I 'm new to front-end . I 'm trying to implement bootstrap 's multi-select component in my page but the problem I 'm facing is that , when I submit my page to server and if error occurs , it removes all the css classes from select box and simply shows a multi-select list instead o...
< spring : bind path= '' userClients '' > < div id= '' customerSelect '' class= '' $ { status.error ? 'has-error ' : `` } '' style= '' margin-top:20px ; margin-bottom:15px height:30px '' > < form : select class= '' selectpicker form-control '' path= '' userClients '' multiple= '' multiple '' name= '' userClients '' > <...
Refreshing page removes bootstrap-select stylings
JS
I try to make a bubble which will be responsive no matter on user device and also it have a triangle on left site.How it should looks like : What I tried : HTML : What does n't work : It looks like bubble it self is responsive correctly , but I have problem with triangle on left site , it 's no on right position depend...
.responsive-bubble { position : relative ; display : inline-block ; max-width : 80 % ; min-width : 80 % ; min-height : 1.5em ; padding : 20px ; background : # ebebeb ; border : # ebebeb solid 4px ; -webkit-border-radius : 20px ; -moz-border-radius : 20px ; border-radius : 0px ; border-style : solid ; float : right ; } ...
How to make responsive bubble with triangle on left site
JS
I want to sort the below array by the `` name '' that is inside `` user '' objecthow can I do this ? I have a method to sort array of objects but I ca n't use it for array of objects of objectsthis is the method : then I can sort using this :
var myArr = [ { `` id '' :1 , '' user '' : { `` name '' : '' allen '' , '' id '' :101 } } , { `` id '' :2 , '' user '' : { `` name '' : '' martin '' , '' id '' :102 } } ] function dynamicSort ( property ) { var sortOrder = 1 ; if ( property [ 0 ] === `` - '' ) { sortOrder = -1 ; property = property.substr ( 1 ) ; } ret...
Sort array of objects of objects in javascript
JS
What does the following javascript do ?
var groups = countrylist.split ( ' , ' ) ; for ( var i = -1 , group ; group = groupsCounty [ ++i ] ; ) { ... }
Javascript - what does this line do ?
JS
My SituationHi , Im relatively new to Javascript so my question could be really easy.Im developing multiple webapps for my company . One problem I run in regularly are Javascript-errors . I know how to handly them using try/catch.What I want to doI want to either write a logfile on the server or give the user something...
< button id= '' demo '' onClick= '' errorHandling ( ) '' > Produce error < /button > < script > function errorHandling ( ) { try { document.getElementById ( `` somethingNotExisting '' ) .value * 2 ; } catch ( _err ) { window.prompt ( `` Copy to clipboard : Ctrl+C , Enter '' , _err.stack ) ; } } < /script > < div id= ''...
How to handle Javascript errors when also using jQuery ?
JS
this following piece of code works , but it sort of makes the browser quirk just a bit . Nothing major . I 'm wondering if there would be a way to make this more efficient ? Can I use caching or somehow populate one select and then just copy it to the other 5 . ( there are 6 drop downs with a class of 'mask ' on the pa...
$ ( '.mask ' ) .each ( function ( ) { $ ( this ) .append ( $ ( ' < option/ > ' ) .val ( `` '' ) .text ( `` '' ) ) ; for ( var i = 1 ; i < 256 ; i++ ) { $ ( this ) .append ( $ ( ' < option/ > ' ) .val ( i ) .text ( i ) ) ; } } ) ; } ) ;
more efficient jquery
JS
I need to store some values in a Vue Component beforeCreate hook that I 'll require later in beforeDestroy . The thing is ( or at least that 's what I understood ) beforeCreate hook does n't have access to reactive data yet . Since I do n't need these values anywhere but in beforeDestroy , I do n't mind them not being ...
Vue.component ( 'my-component ' , { data : function ( ) { return { msg : `` I 'm a reactive value . '' } } , template : ' < div > < div > { { msg } } < /div > < div > { { value } } < /div > < button @ click= '' onClick '' > Click Me < /button > < /div > ' , beforeCreate : function ( ) { this.value = `` I was declared b...
Why is this value reactive if it 's not declared in data ?
JS
I write NodeJS libraries and I usually put JSDoc comments in the code , generating documentation then.So , my code looks like this : When this script will be required from another NodeJS script , will the comment above be loaded in the RAM ? So , do the big comments affect the memory somehow ? I guess the NodeJS script...
/** * Sum * Calculates the sum of two numbers . * * @ name Sum * @ function * @ param { Number } a The first number , * @ param { Number } b The second number . * @ return { Number } The sum of the two numbers . */module.exports = function ( a , b ) { return a + b ; } ; function foo ( ) { // Hello World comment return ...
Is it possible that the comments from a NodeJS script create memory issues ?
JS
Is there a cannonical way of going about doing something like the following without breaking encapsulation ? ReactDOM.findDOMNode seems to be the suggested way of going about this , but this still breaks encapsulation and the documentation has a big red flag to this extent .
import React , { Component , PropTypes } from 'react ' ; class Dashboard extends Component { constructor ( props , context ) { super ( props , context ) ; this.setRef = : :this.setRef ; } componentDidMount ( ) { const node = ReactDOM.findDOMNode ( this.someRef ) ; const newHeight = window.innerHeight - node.offsetTop -...
react - accessing DOM without breaking encapsulation
JS
I am trying to use PageDown on the client side as an editor , and on the server side to then parse that Markdown to HTML.It seems to work fine on the client side , but on the server side , tickmarks are only `` codifying '' the character that follows , not the word that it wraps . So if I do this : test ` test ` testI ...
function getSanitizedHtml ( pagedown ) { var converter = new Markdown.getSanitizingConverter ( ) ; return converter.makeHtml ( pagedown ) ; } < ! DOCTYPE html > < html > < head > < script src= '' pageDown.js '' > < /script > < script > function convert ( ) { var html = getSanitizedHtml ( `` test ` test ` test '' ) ; co...
PageDown through ScriptEngine incorrectly parsing Markdown
JS
I have a select with options and when a user selects an option , it is removed from the select and displayed as a button . When the button is pressed , the option goes back to my select . Everything works fine with mouse click , but if we navigate with the arrows key , the user can select my first option which is `` ch...
< select id= '' combobox '' onchange= '' cbchange ( ) ; '' > < option selected= '' selected '' > Choose Fruit < /option > < option value= '' apple '' > apple < /option > < option value= '' pear '' > pear < /option > < option value= '' orange '' > orange < /option > < option value= '' banana '' > banana < /option > < /s...
Make first option of select unselectable through arrow keys in Google Chrome
JS
I 'm designing a Shiny app to rank people based on a variety of metics . Using the DT sorting feature , I want users to be able to click on any column and sort by it . It seems natural to use the rownames as the rank ; the problem is that these numbers sort along with the rest of the table . Is there any way to freeze ...
# Simplified examplelibrary ( shiny ) library ( DT ) ui < - fluidPage ( DT : :dataTableOutput ( `` table '' ) ) server < - function ( input , output ) { output $ table < - DT : :renderDataTable ( { x < - data.frame ( Name = c ( `` Person A '' , `` Person B '' , `` Person C '' , `` Person D '' ) , Metric_1 = c ( 8 , 7 ,...
Shiny DT : Freeze rownames while sorting ?
JS
I wanted to benchmark the function that I am using to find out if there is a duplicated attribute in an array of objects using map ( ) and some ( ) versus another function that does the same thing but using a for ( ) inside another for ( ) .versus : Using JsPerf I can see that the function that uses map ( ) and some ( ...
let array = [ { `` value '' : 41 } , { `` value '' : 12 } , { `` value '' : 32 } ] ; let itens = array.map ( x = > x.value ) ; let haveDuplicate = itens.some ( ( item , idx ) = > itens.indexOf ( item ) ! == idx ) ; let array = [ { `` value '' : 41 } , { `` value '' : 12 } , { `` value '' : 32 } ] ; let haveDuplicate = ...
Why is the for ( ) function faster than ES6 map ( ) and some ( ) for finding duplicates ?
JS
Example : Given the condition that the host environment is unknown , meaning that we can not assume that the global object will be accessible via the window name . Also , the function is not allowed to receive any arguments !
var test = 'global value ' ; ( function ( ) { var test = 'local value ' ; // how to get the 'global value ' string } ) ( ) ;
How to retrieve the value of a shadowed global variable ?
JS
Using bracket notation , you can initialize an array with zero or more values : Using new Array ( ) , you can initialize an array with zero or two or more values : Referring to the multiple-parameter syntax , in JavaScript : The Definitive Guide , Flanagan writes : Using an array literal is almost always simpler than t...
var a= [ ] ; //length : 0 , no itemsvar a= [ 1 ] ; //length : 1 , items : 1var a= [ 1,2 ] ; //length : 2 , items : 1,2 var a= new Array ( 0 ) ; //length : 0 , no itemsvar a= new Array ( 1 ) ; //length : 1 , items : undefinedvar a= new Array ( 1,2 ) ; //length : 2 , items : 1,2
new Array syntax , multiple parameters
JS
Here is my code output with passing the data to the console : My result is : SyntaxError : unterminated string literal.I understand that this is an issue with breaking new lines in javascript and i need to use \ but this is dynamic data as follows : So , how do I resolve this issue ? The application is not outputting t...
console.log ( 'FUN , FRIENDLY , * New PRIVATE PARTY ROOM with stage , 70 '' Satellite TV , comfortable lounge seatingExciting Bachelor Parties , Unique Surprise Birthday Parties , Divorce , Retirement ... .You Own IT ! Party includes : 90 Minutes Open Bar , Dedicated Waitress , complimentary Dance of choice for the gue...
Unterminated string literal for db data in javascript
JS
I am trying to debug a problem in my app which I have narrowed down to a particular situation involving a regular expression which causes Chrome to choke ! Trying the same code in Firefox works fine . Also if I reduce my 'sample ' text to run the regex on it works too . So what gives ? Here is the jsfiddle : http : //j...
var rgx = /^ ( \d+ ( [ , | ; ] ? \d* ) ) * $ / ; var sample = '40162690,40162755,40162691,40168355,40168357,40162726,40162752,40162729,40428707 ,40162740,40162546 ' ; alert ( `` Test is `` +rgx.test ( sample ) ) ;
Why does this code cause Chrome to choke ?
JS
I have no idea what is happening here . The code is : I would expect this to log in the console : But instead it logs : How is the second named function being created when the code does n't enter that branch ?
if ( true ) { console.log ( 'In first function definition ' ) ; function test ( ) { console.log ( 'Hello world ' ) ; } } else { console.log ( 'In the second function definition ' ) ; function test ( ) { console.log ( 'Goodbye world ' ) ; } } test ( ) ; 'In the first function definition '' Hello world ' 'In the first fu...
Javascript named function definition executed when it should n't
JS
I thought I understand how regex operators work , but now I 'm really confused.In simplified example , I have two strings : I want to match first one , NOT the second.And I 'm writing regex ( simplified version ) like this : And when I run in JS method test on both those examples , it simply returns true ( in sublime 2...
mail.wow.no-1.commail.ololo.wow.com ^mail\. ( .* ) ( ? ! \.wow\.com ) $
How does ( ? ! ) operator in regex work ?
JS
this is the code : code on jsfiddle . On the first run it does n't show the `` slideDown '' animation but subsequent times it works fine .
$ ( `` # more-news '' ) .click ( function ( ) { $ ( `` .news-hide '' ) .slideDown ( 'slow ' ) .removeClass ( `` hide '' ) ; } ) ;
jquery animation does n't work properly on first run
JS
How can I split a string like thisI 'm expecting to get an array with 3 elements :
var str = `` M50 0 L0 100 L100 100 L50 0 z M0 0 L100 0 L50 100 L0 0 Z '' ; var arr4String = str.split ( ' z|Z ' ) ; [ `` M50 0 L0 100 L100 100 L50 0 '' , `` M0 0 L100 0 L50 100 L0 0 '' , `` '' ]
Javascript : split by this|that
JS
After years of creating applications using prototypal inheritance in JavaScript , I 've started to explore using parasitic inheritance . Despite its primary pitfall - at least to me - of potentially creating several copies of methods in memory as you create an object hierarchy , I 'm finding that it really resonates wi...
function foo ( ) { return { method1 : function ( ) { ... } } } function bar ( ) { var that = foo ( ) ; that.method2 = function ( ) { //is `` this '' pointing to bar ( ) ? } return that ; }
What does `` this '' refer to in JavaScript Parasitic Inheritance ?
JS
Here 's my code : What is the proper way to check if 100 milliseconds has passed sense the first time through this function ? In the 5th line of code i have the variable `` something '' which needs to be replaced with a counter of some sort . Or maybe I 'm going about this in an entirely wrong way . Suggestions ?
tripper = 2 ; $ ( `` # topheader '' ) .mousewheel ( function ( event , delta ) { if ( tripper == 2 ) { startPlace = $ ( `` # content '' ) .scrollLeft ( ) ; startCounter = something ; tripper = 1 ; } else { currentPlace = $ ( `` # content '' ) .scrollLeft ( ) ; if ( startCounter < 100 ) { // milliseconds distanceMoved =...
Need help timing events with jquery
JS
I am learning Promise , in order to understand it I read a bit about Event loop of JavaScript . This article briefly introduced the working of event loop such as call stack , event table and message queue.But I do n't know how the call stack deal with the line containing 'return ' , and what happens thereafter.Below is...
var p1 = new Promise ( function ( resolve , reject ) { resolve ( 0 ) ; } ) ; p1.then ( function ( val ) { console.log ( val ) ; p1.then ( function ( ) { console.log ( `` 1.1.1 '' ) ; p1.then ( function ( ) { console.log ( `` 1.1.2 '' ) ; p1.then ( function ( ) { console.log ( `` 1.1.3 '' ) ; } ) ; } ) ; } ) ; p1.then (...
Understanding the execution order of subsequent then ( ) handlers of an resolved promise
JS
How can I put an iframe youtube on a frame with icon close.example : -If I want to put the iframe below on frame with icon close , and if I click on icon close the iframe youtube will disappear , how can I do this ? Thanks
< iframe width= '' 440 '' height= '' 215 '' src= '' http : //www.youtube.com/embed/OyRQio7GfLU '' frameborder= '' 0 '' allowfullscreen > < /iframe >
Put a youtube iframe on an other frame with icon close
JS
My code : I wan na call the close ( ) in get ( ) function like this : I tried to use this but it does n't work.Please give me some advice . Thank you in advance .
export default ( function ( ) { ( ... ) return { open : ( ) = > { ( ... ) } , close : ( ) = > { ( ... ) } , get : ( ) = > { ( ... ) } } } ) ( ) ; get : ( ) = > { close ( ) ; }
How to call function within same module
JS
It is supposed to make an image fly around ( works ) .I added the line marked with the `` ! ! ! -- > '' that should make the image get bigger the closer it is to the bottom of the page.What did I do wrong ? The code does n't throw any errors .
function moveit ( ) { var newTop = Math.floor ( Math.random ( ) *350 ) ; var newLeft = Math.floor ( Math.random ( ) *1024 ) ; var newDuration = 9000 $ ( ' # friends ' ) .animate ( { top : newTop , left : newLeft , ! ! ! -- > width : `` += '' + ( ( newTop- $ ( 'friends ' ) .css ( 'top ' ) ) *3 ) , } , newDuration , func...
What is wrong with this code
JS
What is the practical difference between p and p2 objects here : What are the cases when I would better create new Person ( ) and copy values from parsed JSON , rather than use that parsed JSON object as I would use the instance of Person ? PS . Let 's say I got JSON string from WebSocket and I will have to parse it an...
var Person = function ( name ) { this.Name=name ; } var p = new Person ( `` John '' ) ; var p2 = JSON.parse ( ' { `` Name '' : '' John '' } ' ) ;
Javascript objects parsed vs created
JS
In Android I subclassed ParseObject with two local variables that are not in Parse class . I just needed to set those variables locally and had no need to save them on server . They are String 's named helper1 and helper2 with getters and setters as well.It works all fine on Android - I can use setHelper1 ( `` whatever...
q1.find ( { success : function ( results ) { for ( var x in results ) { x.helper1 = 'foo ' ; } response.success ( results ) ; } , error : function ( error ) { } } ) ;
JavaScript subclassing in Parse.com
JS
I currently have a partial-application function which looks like this : The problem is that it only works for non-member functions , for instance : How can I rephrase the curry function to be applied to member functions , as in :
Function.prototype.curry = function ( ) { var args = [ ] ; for ( var i = 0 ; i < arguments.length ; ++i ) args.push ( arguments [ i ] ) ; return function ( ) { for ( var i = 0 ; i < arguments.length ; ++i ) args.push ( arguments [ i ] ) ; this.apply ( window , args ) ; } .bind ( this ) ; } function foo ( x , y ) { aler...
How to partially apply member functions in JavaScript ?
JS
Are they the same ?
var multiply = function ( ) { //.. } ( ) ; var multiply1 = ( function ( ) { //.. } ( ) ) ;
Parenthesis for anonymous JavaScript functions
JS
Is there a specific reason why I have seen many people writinginstead ofI had given an answer in which I wrote something like Array === obj.constructor which is when someone asked me that he has often seen people writing like this instead of obj.constructor === Array . So does it really matter which way I use ?
if ( 1 === a ) { ... } if ( a === 1 ) { ... }
Javascript : Order of operands in comparison operator
JS
I am confused as to how React functions bind to this.You should see on the console both of these return something , however randomFunction is not present in the previous this object . As show in the image belowI am curious to know how/where this link is made ?
import React , { Component } from 'react ' ; class App extends Component { randomFunction ( ) { console.log ( `` Hello World '' ) } render ( ) { return ( < div > { console.log ( this ) } { console.log ( this.randomFunction ) } < /div > ) ; } } export default App ;
React function not displayed in `` this '' but yet still callable
JS
In my application I have Products table which containing various types of products.In each record have column call updateDetails and it is a JSON object with below attributes.But in some records in Products table updateDetails is null and will be updated after the record edited by any user.My sample DB records as below...
const updateDetails = { time : '2020-05-28T05:53:31.540Z ' , userId : 1 , officeId : 2 } [ { name : 'Product 1 ' , type : ' a ' , updateDetails : { time : '2020-05-28T05:53:31.540Z ' , userId : 1 , officeId : 2 } } , { name : 'Product 2 ' , type : ' a ' , updateDetails : null } , { name : 'Product 3 ' , type : ' a ' , ...
Order records in DESC not working property in SequelizeJS
JS
Сomparing anything with undefined has been discussed many times , but today I had to compare items in arrays and , at some point , items in the array could be undefined and I was curious how they will compare to each other . I found that undefined == undefined is true , but at the same time undefined > = undefined is n...
undefined === undefined : true undefined == undefined : true undefined ! == undefined : false undefined ! = undefined : false undefined < undefined : false undefined > undefined : false undefined < = undefined : false undefined > = undefined : false
Equal but not greater-or-equal ?
JS
I came across the function below in one of the SharePoint system javascript files.I have never seen something like ULS1Lu : ; in any of the javascript code I have worked with before . Does anyone know what this is doing ? Sorry the weak title on the question . I was n't sure how else to phrase it .
function RTE_InsertImage ( strBaseElementID ) { ULS1Lu : ; //A bunch of javascript }
What does this do in javascript ?
JS
I find myself typing this repeatedly for debugging in my code . Is there a way to create a function for this ? I would like to create a function like this : Is there a way to do this ? logVar ( abc ) should return `` abc = 1 '' logVar ( xyz ) should return `` xyz = 2 ''
var abc = 1console.log ( `` abc = `` +abc ) ; var xyz = 2 ; console.log ( `` xyz = `` +xyz ) ; logVar = function ( input ) { console.log ( input.name ( ) + '' = `` +input ) ; }
How to log both variable and its name ?
JS
I created this object and it 's properties : So then I call a for loop on them : Which according to my tutorial , should produce the following results : But instead it only displays value . Why is name not showing up ?
var obj = { } ; Object.defineProperty ( obj , `` value '' , { value : true , writable : false , enumerable : true , configurable : true } ) ; var name = `` John '' ; Object.defineProperty ( obj , `` name '' , { get : function ( ) { return name ; } , set : function ( value ) { name = value ; } } ) ; for ( var prop in ob...
Why is my for loop not working on my Javascript properties ?
JS
I 've written a simple jQuery plugin , but I 'd like to make it more advanced so I can do things like : How can I write a plugin that can be called like this ? -- -- -- -- -- -- -- -- -- -- -- -- -Updated -- -- -- -- -- -- -- -- -- -- -- -- -Thanks @ Craig MacGregor , appreciate it.But to call the function it need to b...
$ .myplugin.close ( ) ; $ .myplugin.open ( ) ; $ .myplugin.next ( ) ; $ .myplugin.prev ( ) ; $ ( this ) .myplugin.load ( ) ;
How do I write a jQuery plugin that is called like ` $ .myplugin.func ( ) ` ?
JS
I created an AngularJS factory that I reuse for data access : Reading a brief write-up on the differences between Angular services , factories and providers , I am a bit confused as to what this factory actually is , based on those definitions.In Summary : Services : provided with an instance of the function.Factories ...
app.factory ( 'abstractFactory3 ' , function ( $ http ) { function abstractFactory3 ( odataUrlBase ) { this.odataUrlBase = odataUrlBase ; } abstractFactory3.prototype = { getList : function ( odataOptions ) { return $ http.get ( this.odataUrlBase , { params : odataOptions } ) ; } , get : function ( id , odataOptions ) ...
Is this an AngularJS service masquerading as a factory ?
JS
What is the most efficient way to filter the list of classes on a given element ? I know I could write a for-loop to go through the ev.currentTarget.classList but I want to know if there 's a better way.EDIT : I 'd like to clarify that I want the alert to tell me `` foo '' and `` bim . '' I do n't want to replace `` ba...
< div class= '' foo bar '' > < /div > < div class= '' bim bar '' > < /div > $ ( `` div.bar '' ) .click ( function ( ev ) { alert ( `` The non-bar class was : '' + ? ? ? ) ; } ) ;
Filter out an element 's classes in jQuery ?
JS
I added a method trigger to the prototype of Object : And then have a `` for in '' loop : But this loop has 6 iterations instead of 5 . The last iteration is with key : Why is the loop iterating over the __proto__ part of the object ?
Object.prototype.trigger = function ( ) { // ... return this ; } ; var obj = { 4 : 15 , 10 : 41 , 11 : 46 , 12 : 51 , 20 : 74 } for ( item in obj ) { foo ( obj [ item ] ) ; } item = `` trigger ''
JavaScript : Why does the `` for in '' loop pick variables from __proto__ ?
JS
I have a file we 'll call file1.ts : I compile this using Webpack and Babel : webpack.config.jsI publish this to npm . Now I want to import it into what we 'll call file2.ts : However , function1 does not exist because if I do , for example import a from 'package ' ; , a is undefined.To resolve this , I decided to crea...
export { default as function1 } from 'function1.ts ' ; export { default as function2 } from 'function2.ts ' ; const path = require ( `` path '' ) ; module.exports = { target : `` web '' , mode : `` production '' , entry : `` ./src/index.ts '' , output : { path : path.resolve ( __dirname , `` ./lib/cjs '' ) , filename :...
How to module.exports another module ?
JS
I tried to replace [ [ with $ { .I am getting the result `` it is $ { $ { test example $ { $ { testing '' but I want the result `` it is $ { test example $ { testing '' .
var str = `` it is [ [ test example [ [ testing '' ; var res = str.replace ( / [ [ [ ] /g , `` $ { `` ) ;
how to replace ' [ [ ' with ' $ { ' in javascript
JS
I am trying to make simple calendar . In my calendar , I have day , day-names , month and month-names component and all I am accessing it on main calendar . When initial load it will show current month calendar.Now when I select month from month-name component want to pass to month component and then pass to day compon...
import * as moment from 'moment'import * as React from 'react'import { showComponent } from '../../../../models'import { MonthNames } from './'import styles from './Calendar.module.scss'interface IDatePickerMonthsProps { changeMonthComponent : ( showComponent : showComponent , monthNo : number ) = > void } interface ID...
Passing Data between react components
JS
Why next code is valid Javascript code ?
var global = ( 1 , eval ) ( 'this ' ) ; alert ( global ) ;
Why this code is valid : `` ( 1 , eval ) ( 'this ' ) ''
JS
Will the following code form a closure ? Does where this function is defined affect the answer ?
function f ( ) { }
Will a simple function declaration form a closure in JavaScript ?
JS
right now i am displaying the live data using d3 and here my requirement is how can i display a small circle at the end of last bar at the right edge and what ever the data may based on last bar i should display on top of it below is snap shotbelow is my js fiddle : - https : //jsfiddle.net/madpop143/5atLwk6h/10/below ...
var margin = { top : 20 , left : 20 , right : 20 , bottom : 20 } ; var width = 750 - margin.left - margin.right ; var height = 750 - margin.top - margin.bottom ; var randomDate = function ( start , end ) { return new Date ( start.getTime ( ) + Math.random ( ) * ( end.getTime ( ) - start.getTime ( ) ) ) ; } ; var data =...
How to set circle at the right end of the last bar / item using D3
JS
I know there is a more readable way of writing this :
var string = ( ( r.d ! = 0 ? r.d + ( r.d == 1 ? ' day ' : ' days ' ) : `` ) + ( r.h ! = 0 ? r.h + ( r.h == 1 ? ' hour ' : ' hours ' ) : `` ) + ( r.m ! = 0 ? r.m + ( r.m == 1 ? ' minute ' : ' minutes ' ) : `` ) + ( r.s ! = 0 ? r.s + ( r.s == 1 ? ' second ' : ' seconds ' ) : `` ) ) ;
a more readable way to do this ?
JS
I would like to understand the following example so it is crystal clear for me . Unfortunately , my head hangs on the line : .forEach ( c = > ( node [ c.id ] = makeTree ( categories , c.id ) ) ) . can someone give me a hint ?
let categories = [ { id : 'animals ' , parent : null } , { id : 'mammals ' , parent : 'animals ' } , { id : 'cats ' , parent : 'mammals ' } , { id : 'dogs ' , parent : 'mammals ' } , { id : 'chihuahua ' , parent : 'dogs ' } , { id : 'labrador ' , parent : 'dogs ' } , { id : 'persian ' , parent : 'cats ' } , { id : 'sia...
Recursion with higher order functions
JS
I 'm learning JavaScript for the first time and I would like to know why my code does n't work.I have Python/Django knowledges.Objective : I have to create a list of names and I have to display only firstnames which begins by ' B ' letter.My script : But this code does n't display something .
var listNames = [ 'Paul ' , 'Bruno ' , 'Arthur ' , 'Bert ' , 'José ' ] for ( var i in listNames ) { if ( i.substr ( 0 , 1 ) === ' B ' ) { console.log ( i ) ; } }
Learning JavaScript : display all firstnames with B as first letter
JS
I have a service in Angular with the following method that fetches data from Firebase : It returns a firebase Observable to which I can apply pipe and subscribe , e.g. , However , when I try instead to return a Query from the database service , the object returned is no longer an Observable : ERROR in src/app/matchData...
getMatchesFiltered ( matchId : string , filter : string , sortDirection : string , pageIndex : number , pageSize : number ) { return this.db.object ( '/matches ' ) ; } this.dbService.getMatchesFiltered ( matchId , filter , sortDirection , pageIndex , pageSize ) .pipe ( catchError ( ( ) = > of ( [ ] ) ) , finalize ( ( )...
What is the analogous way to handle pipe and subscribe for a firebase Query object ?
JS
I have a page name url.com/yourfirstpage/ when i go to the page all the div are hidden by default ( display : none ) if we target # sec1 as url.com/yourfirstpage/ # sec1 it only displays sec1 and hide others.I was wondering if we go the url without having anchor id like url.com/yourfirstpage/ it needs to show all the d...
# sec1 , # sec2 , # sec3 { display : none ; } # sec1 : target { display : block ; } # sec2 : target { display : block ; } # sec3 : target { display : block ; } < a href= '' # sec1 '' > sec1 < /a > < a href= '' # sec2 '' > sec2 < /a > < a href= '' # sec3 '' > sec3 < /a > < div id= '' sec1 '' class= '' page '' > this is ...
Show all div if none of link clicked
JS
Here 's the deal . I am doing some string manipulation and I am using the substr method often . However , the way I need to use it , is more like a php fread method . Whereas , my substr needs to be guided by a pointer . The process needs to act like this : and if I read in , 'Lorem ' ... ..as my first substr call as s...
var string='Loremipsumdolorsitamet , consectetur ' string.substr ( offset , strLenth ) //0,5 offset pointer starts here now= > ipsumdolorsitamet , consectetur ' var _offSetPointer=0var _substrTest= { _offset : function ( ) { return _offSetPointer+=getLength } } ; //usage , where p is the length in bytes of the substrin...
I am trying to create a substr method with a pointer ... . is there a more elegant solution ?
JS
I 'm building an RxJS slideshow where , if user holds the right arrow key , I want to navigate to the next tile at every 500 ms . I 'm using throttleTime like below : What I would like to do now is to reduce the throttleTime to 100ms after I have navigated to the 5th tile without releasing the arrow key.Is that possibl...
const forwardNavigation $ = fromEvent ( document , 'keydown ' ) .pipe ( filter ( event = > event.keyCode === KEY_CODE.arrowRight ) , throttleTime ( 500 ) ) ;
RxJS : Change throttleTime after X emissions
JS
I am stuck showing the cart page where the products are listed which were added to Cart by Users.I have two arrays : One with the product details.Another with Cart Product details which has productID and quantity selected by users only.I have filtered all the products that the user have selected.This function gives the...
productDetails : [ { productID : 1 , productTitle : 'Product Title 1 ' , productPrice : 2000 } , { productID : 2 , productTitle : 'Product Title 2 ' , productPrice : 5000 } , { productID : 3 , productTitle : 'Product Title 3 ' , productPrice : 1000 } , { productID : 4 , productTitle : 'Product Title 4 ' , productPrice ...
Combine two arrays after using filter method
JS
I am streaming audio in my flask app from a client to the server , but the received audio has very low quality.On the client , I preprocess the audio buffer as follows : On the server side , I receive the audio as follows : But the resulting audio sounds metallic , interrupted and noisy . Here 's how the resulting wave...
this.node.onaudioprocess = function ( e ) { var buf = e.inputBuffer.getChannelData ( 0 ) ; var out = new Int16Array ( buf.length ) ; for ( var i = 0 ; i < buf.length ; i++ ) { var s = Math.max ( -1 , Math.min ( 1 , buf [ i ] ) ) ; out [ i ] = s < 0 ? s * 0x8000 : s * 0x7FFF ; } socket.emit ( 'audio event ' , { data : o...
Why does this decrease the audio quality ?
JS
I am trying to make font bold text with text processing instead of using execute.commands . Because I want make another functionality that not in execute.command.Here is the code : I am able to get selected range and I replaced the selected string with < b > tag to get bold font . But the problem is with HTML tags are ...
var selectedRange ; var selectedText = `` ; let editor = document.getElementById ( 'editor ' ) String.prototype.replaceBetween = function ( start , end , what ) { return this.substring ( 0 , start ) + what + this.substring ( end ) ; } ; function actionBold ( e ) { let input = e.getElementsByTagName ( 'input ' ) [ 0 ] i...
How to make bold text in content editable div with raw text processing
JS
I have a webpage that updates via ajax . It loads updated news feeds every 1 minute . What I want to do is create a javascript that detects the incoming date field and put a strong tag around it . Here 's a sample of the html that gets feed through : I can write the basic javascript that updates it , but it only fires ...
< div class= '' results '' > < div class= '' article '' > < div class= '' date '' > jan 8 , 2013 < /div > < p > Some content here < /p > < /div > < div class= '' article '' > < div class= '' date '' > feb 8 , 2013 < /div > < p > Some content here < /p > < /div > < /div >
How to create a persistent javascript where it updates when content is constantly updated via ajax ?
JS
I have multiple div tags : The main div that holds the content , if the content gets bigger , the height will obviously get bigger too , but the other divs don't.How do I make the other divs take the main div 's height ? CodeCSSCurrently it looks like this : As you see the div that holds the content gets the height , b...
< div id= '' container '' > < span id= '' header '' > Fiction Tools < /span > < span id= '' paragraph '' > Lots of text will be in this text box , describing in great detail the awesomeness of Fiction Tools and it ’ s capabilities . Fiction Tools is known for lots of awesome things , here are a few : < /span > < ul id=...
Div takes the same height of other div
JS
I wrote a game class with coffeescript that displays a plain and a rotating cube . You can see the code here : http : //jsfiddle.net/6eRzt/6/All is dandy , except for two things:1 ) I have to do an ugly hack to get the requestAnimationFrame callback working:2 ) This is my major concern : The SpotLight does not work . I...
var sh = new App ( ) ; sh.start ( ) ; function animate ( ) { sh.animate ( ) ; requestAnimationFrame ( animate ) ; } animate ( ) ; ​
Why does n't the light in this scene work ?