Splicing items from an array in a for loop, get typeerror

For an application I am making I want to remove items from an array using checkboxes. This is the function I use:

    for(let article = articleList.length -1; article >= 0; article--)
  
  {
    console.log(article, articleList[article].props.title);
    if(this.whatToShow.article == false){
      if (articleList[article].props.category == "Artikel"){
        articleList.splice(article, 1);
      }
    }
    if(this.whatToShow.news == false){
      if (articleList[article].props.category == "Nieuws"){
        articleList.splice(article, 1);
      }
    }
    if(this.whatToShow.blog == false){
      if (articleList[article].props.category == "Blog"){
        articleList.splice(article, 1);
      }
    }
    if(this.whatToShow.client == false){
      if (articleList[article].props.category == "Client"){
        articleList.splice(article, 1);
      }
    }
    if(this.whatToShow.stories == false){
      if (articleList[article].props.category == "Ervaringsverhaal"){
        articleList.splice(article, 1);
      }
    }
  }

I first had the problem that it wouldn’t remove all the items, so I made the loop backwards. Now when I have almost all checkboxes off (all values false) I get a typeerror, but I have no idea what’s going wrong here. Can anyone help me?

Thank you in advance 🙂

Merge objects in array of objects based on id

I have an array of objects like this
How to achieve output form of this array ?
Input:

[
 { meta_key: 'nickname', meta_value: 'testqa2', id: '10' },
  { meta_key: 'first_name', meta_value: 'TEST', id: '10' },
  { meta_key: 'last_name', meta_value: 'QA', id: '10' },
  { meta_key: 'nickname', meta_value: 'testqa10', id: '11' },
  { meta_key: 'first_name', meta_value: 'TEST', id: '11' },
  { meta_key: 'last_name', meta_value: 'QA', id: '11' }
]

Output

[
 {id:'10 , nickname:'testqa2 , first_name:'TEST' , last_name :'QA'},
 {id:'10 , nickname:'testqa10, first_name:'TEST' , last_name :'QA'}
]

How to implement rolling a ball on a sphere in terms of matrices?

Target:
It is necessary to create two spheres, one of which can be rolled over the surface of the other with the mouse, and implement a camera that can be moved around these balls using the keyboard.

Implementation:
I started a matrix that stores the current state of the rotation of the rolling ball. When the user drags, I get a series of mouse move events, and each time I move, I calculate how many degrees around the current X and Y, as the user sees them, the rotation has changed. Then I calculate a matrix that represents these two rotations and multiply the original sphere rotation matrix by it in reverse order – the reverse order is necessary because the rotation occurs from the point of view of the camera, and not from the point of view of model space.

Problem:
But with such an implementation, the second sphere will not change the point of contact with the first sphere (it will, as it were, slide along it), how can one analytically implement the rotation of the point of contact of the balls in terms of matrices?

Here is the code if anyone is interested: https://github.com/AndrewStrizh/spheres-with-webGL

How to test callback methods in react functional component when the child component elements are not completely accessible

I am using jest to test my react component. However I need to test the callback methods passed as props to children components.
My component looks something like this

    function myReactComp = (props) =>  {
      onRowEditHandler = (rowData) => {
        // if this then that logic
        // process and trasform data
        // set some local state
        // dispatch action
      }
      
      return (
         <ComplexDataTableComponent data={someDataProps} onRowEdit = {onRowEditHandler} />
     )
    }

I need to test the onRowEditHandler as a function. I want to send arguments to this function explicitly so that specific code logic are triggered.

Now many suggestions in stackOverflow says, the best way to test closure functions in react functional components is to simulate the user behavior. For example, if there is a callback for a button, find the button on the wrapper/instance and trigger the click event.

In my case, the ComplexDataTableComponent is kind of like a container, which has many children and nested components. It is next to impossible to find a specific row element, trigger its edit button and then update the form data so that the call back is triggered.

Is there any way i can get access to onRowEditHandler apart from triggering the wrapper/instance elements?

Show progress bar on scroll for a specific div

I want to display a progress bar while the user is scrolling, I want this progress bar to be based on a specific div, which means the progress bar should be 100% when the user scrolled to the end of the div.

Here is a fiddle: https://jsfiddle.net/tvmkf4ds/

Here is the code I use:

$(document).scroll(function () {
  var scroll = $(this).scrollTop();
  var $main = $('#scroll');
  var offsetTop = $main.offset().top;
  var offsetBottom = $main.offset().bottom;
  var height = $main.height();

  var percent = scroll - (offsetTop) / height * 100;

  $("#progress-bar-value").css('width', percent);
});

The problem is the bar is not 100% filled when you scroll at the end of #scroll element, but only when you scroll until end of page.

I tried too:

var percent = scroll - (offsetTop - offsetBottom) / height * 100;

But I can’t figure out the good calculation.

Adjusting the table headers on Kintone JSedit

So far, my main problem is that I am trying to adjust a table on Kintone.
I have been able to access the contents of the table (when you add table elements to it, you can see the colors changing, however the headers themselves do not seem to change).

Currently, I am using Kintone (Cybozu), however since it is using JSEdit, I think the problem can be solved with Javascript knowledge (which I very much do not have).

What do I want to do?

(please see the attached pictures)
Center, bold, and other adjustments to those headers.
If my code is completely wrong, please do ignore it and any code that will help this situation would be greatly appreciated.

enter image description here

enter image description here

How to trigger JS code when a link inside Android WebView is clicked?

I have run into a problem and couldn’t find a working solution. I want to hide Download Mobile App in my Andriod webview app with the following code:

        final String javascript = "var myClasses = document.querySelectorAll('.mobileBTN'),i = 0,l = myClasses.length; for (i; i < l; i++) {myClasses[i].style.display = 'none';}";
        webView.setWebViewClient(new WebViewClient() {
            public void onPageFinished(WebView webview, String url) {
                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
                    webview.evaluateJavascript(javascript, null);
                } else {
                    webview.loadUrl("javascript:(function(){" + javascript + "})()");
                }
            }
        });

The code works just fine and hides the Download Mobile App buttons on the app (homepage) but when a link inside the webview is clicked, say for example, the About Us link is clicked, then on that new page, the JS code which hides the Download Mobile App buttons doesn’t work anymore.

How can I get the JS code above to run every single time when a link inside the webview is clicked?

I’ve tried the following code from another answer on StackOverFlow but is not working for me:

            public void onLoadResource(WebView  webview, String  url){
                if( url.equals("https://test.com/aboutus.html")){
                    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
                        webview.evaluateJavascript(javascript, null);
                    } else {
                        webview.loadUrl("javascript:(function(){" + javascript + "})()");
                    }
                }
            }

Note: I’m using Andriod Studio for the app.

Typed default exports in typescript?

I tried searching for this but couldnt find it. I’m trying to do this

import { Variables } from './types';


export default: Variables = {
  type: 'set_variables',
  variables: {
    show_cursor: false,
    win_size: 400,
    is_text_only: false,
    type_time: 0.05,
  },
};

getting syntax errors. Do I have to first set it as a variable and then export the variable as default?

Angular 12: ERROR TypeError: Cannot read properties of undefined (reading ‘nativeElement’)

I have phone number input field in which I have attached prefixes dropdown. Below is code for that.

HTML

<div
              class="phone"
              [ngClass]="{ 'error_border': submitted && f.phoneNumber.errors }"
            >
              <div class="phone__select">
                <span class="phone__prefix" (click)="openPrefixes()"
                  >{{ selectedPrefix }}</span
                >
                <ul #prefixes class="prefixes">
                  <li
                    *ngFor="let prefix of availablePrefixes"
                    class="prefix"
                    (click)="prefixChange(prefix)"
                  >
                    {{ prefix }}
                  </li>
                </ul>
              </div>
              <input
                class="phone__input form-control"
                maxlength="13"
                type="text"
                pattern="^(?!0+$)d{10,}$"
                formControlName="phoneNumber"
              />
            </div>

TS

 @ViewChild("prefixes") prefixes!: ElementRef;
  selectedPrefix = "+43";
  availablePrefixes = ["+43", "+49"];
  
  prefixChange(prefix: string): void {
    this.selectedPrefix = prefix;
    this.closePrefixes();
  }

  openPrefixes(): void {
    this.renderer.addClass(this.prefixes.nativeElement, "active");
  }

  closePrefixes(): void {
    this.renderer.removeClass(this.prefixes.nativeElement, "active");
  }

Above code works fine on page but its giving error like ERROR TypeError: Cannot read properties of undefined (reading 'nativeElement') when I use above code on modal.

When modal opens prefix dropdown is not working and showing that error.

How should I resolve above error? Is there any alternative way to do this (e.g. using ngModal) ?

Please help and guide.

EventSource for fixed seconds in Javascript

I’m newbie to the feature of EventSource in javascript. As per my understanding the eventsource calls the api with stream content and gets the updates of data automatically without making any further calls. But I’m planning to make if possible to stop listening the response after 10 seconds from the EventSource. For Example in the below URL we can find the EventSource example, I want it to get stopped listening/fetching after 10 seconds.

https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_sse

how can use if to compare text

how to use if to change result
i need to change my result if i change range (D7) but it’s not working,i need to get value 1,2,4 if D7=”order” & get value 10 if D7=”Refund”, so how use if to compare “order” with D7 ?

my code

    //Function to Search the record

function searchRecord() {
  
  var myGooglSheet= SpreadsheetApp.getActiveSpreadsheet(); //declare a variable and set with active google sheet 
  var shUserForm= myGooglSheet.getSheetByName("User1"); //delcare a variable and set with the User1 worksheet
  var datasheet = myGooglSheet.getSheetByName(shUserForm.getRange ("D4").getValue()); ////delcare a variable and set with the Database worksheet

  var workingcell = shUserForm.getRange("D7").getValue();  
  var str       = shUserForm.getRange("C4").getValue();
  var values    = datasheet.getDataRange().getValues(); //getting the entire values from the used range and assigning it to values variable
  var valuesFound=false; //variable to store boolean value
  
  for (var i = 0; i < values.length; i++) 
    {
    var rowValue = values[i]; //declaraing a variable and storing the value
   
    //checking the first value of the record is equal to search item
    
    if (workingcell === "order" ) {

      shUserForm.getRange("C9").setValue(rowValue[1]);
      shUserForm.getRange("C11").setValue(rowValue[2]);
      shUserForm.getRange("C13").setValue(rowValue[4]);
      shUserForm.getRange("C15").setValue(rowValue[5]);
    }
    else if(workingcell === "refund" ) {

      shUserForm.getRange("C9").setValue(rowValue[10]);
    }

    if (rowValue[0] == str) {
           
      
      shUserForm.getRange("C9").setValue(rowValue[14]);
      return; //come out from the search function
      
      }
  }

if(valuesFound==false){
  //to create the instance of the user-interface environment to use the messagebox features
  var ui = SpreadsheetApp.getUi();
  ui.alert("No record found!");
 }

}

Concatenate elements of an array with single quotes and comma

I am trying to create a dynamic SQL query in a Snowflake procedure. The user will pass the names of the customers that need to be retrieved as an array. This needs to be used with the IN clause of the SQL query.

A sample query would look like:

SELECT id
FROM customers
WHERE name IN ('John', 'Jane')

The function looks something like this:

function query(names) {
    
    let inClause = ...;

    query = `
    SELECT id
    FROM customers
    WHERE name IN (${inClause})
    `;

    return query;
}

I would like to generate the inClause from the names array passed as an argument.

How do I concatenate the elements of an array with single quotes and comma so that it forms a proper SQL query?