Odellrubengladys's Profile

180
Points

Questions
34

Answers
40

  • member === bot is not the right way to check if a member is a bot. Remember, the === sign checks if the variables on the two sides of it are equal (in the case of triple equals, also checks if they are of the same type). bot is not a variable that you have declared, so this isnt how you do it.

    Instead, check the user property of the member, which is the user behind the member object. Checking the documentation you’ll find that the user has a boolean property called bot which tells if you if it is a bot or not. Thus the right way to check if the member is a bot is by:

    if(member.user.bot === true) {     //Do stuff } 

    Or of course, simplified:

    if(member.user.bot) {     //Do stuff } 
    • 77 views
    • 2 answers
    • 0 votes
  • It also can be reached by try with resources, something like

      try (       fos = new FileOutputStream(zipFile);         zos = new ZipOutputStream(fos)     ) {     your code         } 
    • 115 views
    • 2 answers
    • 0 votes
  • Asked on July 16, 2020 in Java Script.

    It’s an old question, however might be useful for someone like me.

    lodash has _.inRange() function https://lodash.com/docs/4.17.4#inRange

    Example:

    _.inRange(3, 2, 4); // => true 

    Please note that this method utilizes the Lodash utility library, and requires access to an installed version of Lodash.

    • 89 views
    • 7 answers
    • 0 votes
  • This is an implementation detail and so there are no real guarantees. That said we try to minimise the memory copies as much as possible within Netty.

    • 110 views
    • 1 answers
    • 0 votes
  • It’s because when you enter a number then press Enter, input.nextInt() consumes only the number, not the “end of line”. When input.nextLine() executes, it consumes the “end of line” still in the buffer from the first input.

    Instead, use input.nextLine() immediately after input.nextInt()

    • 189 views
    • 19 answers
    • 0 votes
  • Asked on July 16, 2020 in Java Script.

    This is just a test to see if jPO’s answer works and in fact it does. You probably have an error in the markup. Would you mind to share your html?

    function functionA(event) {    // implement your logic here   console.log('function A called');    // and call functionB as well    functionB(event); }   function functionB(event) {   // implement your B logic here      console.log('function B called'); }  $(document).on('click', '.classA1, .classA2, .classA3', functionA); $(document).on('click', '.classB1, .classB2', functionB);
    a {   display: inline-block;   background: teal;   padding: .5rem;   border-radius: 5px;   color: white;   font: 16px Arial, sans-serif;   cursor: pointer; } .b {   background: orange; }
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <a class="classA1">class A1</a> <a class="classA2">class A2</a> <a class="classA3">class A3</a>  <a class="classB1 b">class B1</a> <a class="classB2 b">class B2</a>

    • 69 views
    • 2 answers
    • 0 votes
  • Asked on July 16, 2020 in Java Script.

    Please check this https://api.jquery.com/jQuery.map/. As it says in callback function it will have first parameter as object and second as index.

    let m = {   data: [    {Id: 600, Name: "rety", Description: "ssa", Number: 135, type: "meter"},    {Id:624, Name: "xyz", Description: null, Number: 134, type: "PC"},    {Id: 645, Name: "abcd", Description: null, DNumber: 142, type: "pcs"},    {Id: 664, Name: "dfdf", Description: null, Number: 134, type: "PC"}   ] };  // set property name into object to updte dynamical property let propName = 'Name';  var _newarray = $.map(m.data, function(obj) {   // copy object with Object.assign   let newObj = Object.assign({}, obj);   // update required property. Use propName to set property   newObj[propName] = 'new value - ' + obj[propName];   // return object   return newObj; });  console.log(_newarray);
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>

    • 83 views
    • 2 answers
    • 0 votes
  • Asked on July 16, 2020 in Java.

    Pass the symbol and the math operation to the super constructor:

    public Multiply(Expression leftExp, Expression rightExp){     super(leftExp,rightExp, " * ", (a, b) -> a * b); } 

    and

    public Divide(Expression leftExp, Expression rightExp){     super(leftExp,rightExp, " / ", (a, b) -> a / b); } 

    Then you can store these parameters in appropriate fields, and use them in the methods, e.g.

    return leftExpString + symbol + rightExpString;  return fn.apply(this.leftExp.calculate(map), this.rightExp.calculate(map)); 
    • 113 views
    • 1 answers
    • 0 votes
  • Asked on July 15, 2020 in Java Script.

    When you use the g flag for your regex, it returns an array of matches, so you can get the first match by using [0]. For assigning one key, you don’t need Object.assign:

    const arr = ["1 apple", "2 watermelon"]; const object = {};  arr.forEach(a => {     let value = a.match(/\d+/g)[0];     let key = a.match(/\D+/g)[0];     object[key] = value; }); 

    This still has the issue of the leading space being in the string, so you could say value = a.match(/\D+/g)[0].substr(1);, or if you’re guaranteed to have the words separated by a space you could just split on space:

    const arr = ["1 apple", "2 watermelon"]; const object = {};  arr.forEach(a => {     const [value, ...keys] = a.split(" ");     object[keys.join(" ")] = value; }); 
    • 92 views
    • 4 answers
    • 0 votes
  • You Should know about “this” Keyword.

    As per my view you can implement “this” in three ways (Self/Arrow function/Bind Method)

    A function’s this keyword behaves a little differently in JavaScript compared to other languages.

    It also has some differences between strict mode and non-strict mode.

    In most cases, the value of this is determined by how a function is called.

    It can’t be set by assignment during execution, and it may be different each time the function is called.

    ES5 introduced the bind() method to set the value of a function’s this regardless of how it’s called,

    and ES2015 introduced arrow functions which don’t provide their own this binding (it retains the this value of the enclosing lexical context).

    Method1: Self – Self is being used to maintain a reference to the original this even as the context is changing. It’s a technique often used in event handlers (especially in closures).

    Reference : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this

    function MyConstructor(data, transport) {     this.data = data;     var self = this;     transport.on('data', function () {         alert(self.data);     }); } 

    Method2: Arrow function – An arrow function expression is a syntactically compact alternative to a regular function expression,

    although without its own bindings to the this, arguments, super, or new.target keywords.

    Arrow function expressions are ill suited as methods, and they cannot be used as constructors.

    Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

      function MyConstructor(data, transport) {     this.data = data;     transport.on('data',()=> {         alert(this.data);     }); } 

    Method3:Bind- The bind() method creates a new function that,

    when called, has its this keyword set to the provided value,

    with a given sequence of arguments preceding any provided when the new function is called.

    Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind

      function MyConstructor(data, transport) {     this.data = data;     transport.on('data',(function() {         alert(this.data);     }).bind(this); 
    • 238 views
    • 11 answers
    • 0 votes