Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Dec 21 2018 17:11
    @MadLittleMods banned @OmarAlmaqtri
  • Jun 05 2018 23:13
    @MadLittleMods banned @LWSS
  • May 25 2018 16:50
    @MadLittleMods banned @TheRedstoneTaco
Aspire
@joinAspireApp_twitter

Me & my buddy built this quick project last week: https://aspire.app/.

Basic idea: a beautiful homepage for developers that you can rapidly customize

We'd really appreciate any feedback & advice!! :)

PS Built with Javascript & Pizza :P

kevin
@kevinJ045
Hey every1
Julian Gonggrijp
@jgonggrijp
Hi @kevinJ045 :wave:
rukkho
@rukkho
Hi @MadLittleMods, and all developers on board. please help me out. Hi guys /n I'm building a reactjs calculator. I have problem with updating the input in my handleContent(). Actually the content holds the value of all buttons. But I have problem with updating my input with the setInput . Please can anyone show/suggest how to target the value of the content so that this will display the updated input each time I press any button? please here is my github repo: https://github.com/rukkho/calculator/tree/main/src . Please try to check my gh-pages at https://rukkho.github.io/calculator/ to notice its weird performance at this stage of the build. Please I really need your help. Thanks in advance!
kirvres
@kirvres
Hi everyone.....I wanted to fetch values of more than one column at a time and need to check if entered input (substring) is present inside all of these column values....anyone can suggest how to implement it inside Cypress? I mean how to write or return promise in this case?
Nadia
@nadiaschutz
hey guys how do i fix recursion error
Obj.prototype.something = function(item) {
  for (var i = 0; i < this.links.length; i++) {
    var link = this.links[i];
    if (link === item ) {
      return true;
    } else if (link.something(item)){
        return true;
    }
  }
  return false;
};
Nadia
@nadiaschutz
var foo = new Obj;
var bar = new Obj;
var baz = new Obj;
var qux = new Obj;

// Connect the nodes baz => bar => foo => qux => bar.
baz.something(bar);
bar.something(foo);
foo.something(qux);
qux.something(bar);

console.log(qux.something(baz));
Julian Gonggrijp
@jgonggrijp

@nadiaschutz You would have to keep track of which nodes you already visited so you don't recurse into them again. If you can afford to use a polyfill (or support only new browsers/engines), then you can use a Set for this:

Obj.prototype.something = function(item, visited = new Set()) {
  if (visited.has(this)) return false;
  visited.add(this);
  for (var i = 0; i < this.links.length; i++) {
    var link = this.links[i];
    if (link === item ) {
      return true;
    } else if (link.something(item, visited)){
        return true;
    }
  }
  return false;
};

If you can't afford to use this new feature, you can set a temporary mark on each visited link and keep track of the objects you marked so you can remove all marks at the end. This gives you the same efficiency (it's basically the approach WeakSet would take behind your back), but it requires a wrapper method in order to handle the administration.

Obj.prototype.something = function(item) {
  var visited = [], result = this._something(item, visited);
  for (var i = 0, l = visited.length; i < l; ++i) {
    delete visited[i].__VISITED_SOMETHING;
  }
  return result;
};

Obj.prototype._something = function(item, visited) {
  if (this.__VISITED_SOMETHING) return false;
  this.__VISITED_SOMETHING = true;
  visited.push(this);
  for (var i = 0; i < this.links.length; i++) {
    var link = this.links[i];
    if (link === item ) {
      return true;
    } else if (link._something(item, visited)){
        return true;
    }
  }
  return false;
};

As a final remark, you might want to check whether this itself is item. That would also simplify the inner loop.

Nadia
@nadiaschutz
@jgonggrijp Thank you! it solves the issue. where can i read/learn more about this stuff?
Julian Gonggrijp
@jgonggrijp
Well MDN covers everything from the JavaScript standard, such as Set. As for algorithms, you can read Underscore if you like. It's readable and it has lots of algorithmic patterns that might inspire you.
Montassar Ben Dhifallah
@Momentum-TN

Hey guys, I am a beginner in JS. I am sending and receiving data from a server using websocket. I have this block of code.

var ws = new WebSocket('ws://' + document.domain + ':' + location.port + '/ws');

      var button = document.getElementsByClassName('mybutton')[0];
      button.onclick = function() {
        var signal = "go";
        ws.send(signal);
      };

var source_json = new Promise(function(resolve,reject) {
        ws.onmessage = function (event) {
          var response = event.data
          var source = JSON.parse(response)
          resolve(source)
        };
      })

then I have this block:

  var x = source_json.then(function (source) {
    //display source in the DOM
  }

my question is : does the x block run only one time or it will be executed every time the socket receives some data ?

NullSense
@SenseNull_twitter
Hi, have a question about code structure, I'm making a clicker game and wondering how to best structure the data, I have a player class that can buy generators. I am wondering how to get access to the price of the generators without initializing them. Or maybe how to reorganize completely
1 reply

Stephen James
@sjames1958gm
@Momentum-TN a promise can only be resolved once.
António Oliveira
@apspoliveira
what's the coding website you recommend to learn javascript?
Montassar Ben Dhifallah
@Momentum-TN
Hey @sjames1958gm, hope you are well :D
Thank you again for your non-stop help
Julian Gonggrijp
@jgonggrijp
@apspoliveira How far are you in your study path, what other languages do you know (if any) and what style of learning do you prefer?
António Oliveira
@apspoliveira
I like those web platforms that evaluate our solution. I would say I am junior programmer, I know more about C# as I prefer Object Oriented Languages
Julian Gonggrijp
@jgonggrijp
@apspoliveira Perhaps Project Euler or edabit?
António Oliveira
@apspoliveira
@jgonggrijp Edabit is paid, perhaps Project Euler.
Montassar Ben Dhifallah
@Momentum-TN
Hey guys, hope you are all well.
How to decode and display a tiff image in the browser using javascript ?
I found these libraries on github, but it seems they don't work: https://github.com/seikichi/tiff.js and https://github.com/GPHemsley/tiff-js
Julian Gonggrijp
@jgonggrijp
@Momentum-TN Perhaps a bit of a non-answer, but I'd be more inclined to "bounce" the image against an API that will do the conversion for me server side, with a tool like ImageMagick. Failing that, I would look for a JS library that can do the job client side, like you did, but I've never tried that.
svimanet
@svimanet:matrix.rongepaadl.com
[m]
Hi, I'm currently calling a redux action when expanding an interface. But the redux action is asynchronous and data does not reach state before the collapse/expand event is complete. What are my options to await state data before continuing operation?
1 reply
Tirlochan Arora
@tirlochanarora16
Hey everyone, wanna learn how to use Node js with Google Sheets? Checkou this link: https://javascript.plainenglish.io/how-to-use-node-js-with-google-sheets-c256c26e10fc
Joseph Henshaw
@Big-jo
please, in feathers.js I'm trying to populate a field returned after creating a document, how do I go about that ?
Justoverclock
@justoverclockl
hi guys, can anyone help me to replace math.floor with window.crypto?
Julian Gonggrijp
@jgonggrijp
@justoverclockl are you looking for documentation like this?
Justoverclock
@justoverclockl
yep but i've tryed, without success
Julian Gonggrijp
@jgonggrijp
@justoverclockl So did my link answer your questions or not?
Justoverclock
@justoverclockl
Sorry for the delay, yes this help me a lot
But now i have another question
const regex = new RegExp('\b(' + Object.keys(mappings).join('|') + ')\b(?![^<]>|[^<>]</[^p])', 'gi');
How could i use this to math only one word (and not all the same words in the same sentence), i need only one
Julian Gonggrijp
@jgonggrijp

@justoverclockl General tip, you can add correct whitespace and syntax highlighting by putting your code between code fences like this:

```js
// your code here
```

I'm using that below to reproduce your regex:

const regex = new RegExp('\b(' + Object.keys(mappings).join('|') + ')\b(?![^<]>|[^<>]</[^p])', 'gi');

I suspect removing the g flag might do the job (so the second argument becomes just 'i').

Justoverclock
@justoverclockl
thank u so much!
Julian Gonggrijp
@jgonggrijp
@justoverclockl Welcome!
Justoverclock
@justoverclockl
as u can see now it works pretty well except for the data-tooltip. It goes offscreen on mobile only. I think its not possible to fix this with css, maybe is possible with javascript. any advice on this?
1 reply
Verratdreizhen
@Verratdreizhen
Good morning am new here
Julian Gonggrijp
@jgonggrijp
hi @Verratdreizhen :wave:
Travis Boss
@travisboss
  const dropDownSelector = "div.coveo-facet-header";
  const parentDropDownSelector = "div.CoveoFacet"
  const activeClass = "is-active";
  const container = document.querySelector(".coveo-facet-column");
  const coveoFilterDropdowns = container.querySelectorAll(dropDownSelector);

  console.log(coveoFilterDropdowns);

  const onClick = ({ target: coveoFilterDropdown }) => {
    container
      .querySelector(`${dropDownSelector} ${activeClass}`)
      ?.classList.toggle(dropDownSelector);
    coveoFilterDropdown.closest(parentDropDownSelector).classList.toggle(activeClass);
  };

  coveoFilterDropdowns.forEach((coveoFilterDropdown) => {
    coveoFilterDropdown.addEventListener("click", onClick, {
      passive: true,
    });
  });
I have this bit of code and in the onClick I need to remove the previous activeClass when I click on a new dropdown, anyone have insight on how i can accomplish this?
Gourab Mahapatra
@mgourab:matrix.org
[m]
hello everyone !
I am new to programming and have been learning javascript. I have a small doubt.
when should I use 'var' and 'let' keyword? please help
Justoverclock
@justoverclockl
@mgourab:matrix.org difference between let and var is that scope of a variable defined with let is limited to the block in which it is declared while variable declared with var has the global scope.
2 replies
@jgonggrijp i have a regex that find and replace hashtag into links, but how can i parse only element inside a specific div/class/id?
21 replies
Gourab Mahapatra
@mgourab:matrix.org
[m]
ok
please wait
function discountPrices(prices, discount) {
  console.log(discounted);   // shows this as undefined
  var discounted = [];      // blank array which will hold our discounted values

  for (var i = 0; i < prices.length; i++) {
    var discountedPrice = prices[i] * (1 - discount);
    var finalPrice = Math.round(discountedPrice * 100) / 100;
    discounted.push(finalPrice);
    console.log(i, discountedPrice, finalPrice);
  }

  console.log('total iterations: ' + i);    // 3
  console.log('last discounted price is: ' + discountedPrice);   // 150
  console.log('last final price is: ' + finalPrice);    // 150

  return discounted;
}

var newResult = discountPrices([100, 200, 300], .5);
console.log('this is our discounted array: ' + '[' + newResult + ']');
Justoverclock
@justoverclockl
put your code inside ```
Gourab Mahapatra
@mgourab:matrix.org
[m]
oh ok