Scrolling height on SVG animation

I am trying to make my SVG animate while scrolling, which works however I cannot figure out how to make sure its contained in my browser view. Need to be able to see scrolling in real time

Heres my issue:
When my browser is full zoomed out, the scrolling animation works EXACTLY as I want it to:
https://imgur.com/a/1A5sTv4

When my browser is at 100% the animation does not work the same way:
https://imgur.com/a/QKk2r7Y

Heres my SVG:

    <svg id="path" viewBox="0 0 1080 1195" fill="none" xmlns="http://www.w3.org/2000/svg">
        <path d="M0 0L949.322 446.411L187.627 745.034L1080 1195" stroke="#FF0000" stroke-width="5"/>
    </svg>

Here is my JS as well:

// Get a reference to the <path>
let path = document.querySelector('path');

// Get length of path... 
let pathLength = path.getTotalLength();

// Make very long dashes (the length of the path itself)
path.style.strokeDasharray = pathLength + ' ' + pathLength;

// Offset the dashes so the it appears hidden entirely
path.style.strokeDashoffset = pathLength;

// When the page scrolls...
let scrollAnimation = () => {

  window.addEventListener("scroll", function(e) {
    
    // What % down is it? 
    let scrollPercentage = (document.documentElement.scrollTop + document.body.scrollTop) / (document.documentElement.scrollHeight - document.documentElement.clientHeight);
    
    // Length to offset the dashes
    let drawLength = pathLength * scrollPercentage
    
    // Draw in reverse
    path.style.strokeDashoffset = pathLength - drawLength;
    
    // ... at bottom of scrolling function
    
    // When complete, remove the dash array, otherwise shape isn't quite sharp
    if (scrollPercentage >= 0.99) {
      path.style.strokeDasharray = "none";
    } else {
      path.style.strokeDasharray = pathLength + ' ' + pathLength;
    }
  });
}

scrollAnimation();

This is the tutorial i tried to follow while implementing my own needs:
https://css-tricks.com/scroll-drawing/

Any help here is greatly appreciated!

Log message printed for promises during a `push` to an array but not a call to `Promise.all`

I’m trying to understand something about the following behavior for promises.

When I push a promise to the promises array, the console.log is executed. I think this is because as I push, I actually execute the promises.

But then when I try doing Promise.all, I don’t see the same console.log messages being printed, it’s just silence. I can see the return values of each resolve if I destructure them from the Promise.all and console.log them, but, again, I don’t see the console.log messages (such as Printed for promise A during push).

Why is this happening?

import * as React from "react";

const promiseA = async ({}) => {
  return await new Promise((resolve) => {
    console.log("Printed for promise A during push");

    resolve("promise a resolved");
  });
};

const promiseB = async ({}) => {
  return await new Promise((resolve) => {
    console.log("Printed for promise B during push");

    resolve("promise b resolved");
  });
};

const Component = React.memo(() => {
  React.useEffect(() => {
    init();
  }, []);

  const init = React.useCallback(async () => {
    let promises = [];
    promises.push(promiseA({})); // 'Printed for promise A during push'
    promises.push(promiseB({})); // 'Printed for promise B during push'

    await Promise.all(promises); // silence, nothing is printed

    /*
        // And if I do the following, I see the strings in `resolve`:
        const [responseA, responseB] = await Promise.all(promises);
    
        console.log("responseA", responseA); // responseA promise a resolved
        console.log("responseB", responseB); // responseB promise a resolved
    */
  }, []);

  return <div />;
});

export default Component;

Why does this website appear blank when viewing the map on a mobile phone, but it is normal when viewing it on a desktop?

I have developed a service website for finding bicycle rental stations, this is my practice work.

But when I encountered a strange situation, I shared this website to my friends on facebook and other social apps. Some friends responded that the map was blank when they opened it, but it was normal to view it on a computer. The computer can see the map normally!

Would you like to know what might be the cause? Thank you for watching my question. If you know the possible reason, please share with me. I will be very grateful for your help, thank you.

https://superawei.github.io/FINDBIKE/

add new class to children container in html/css with javascripth

I’m a beginner in using javascript with html and css. I want to try is there a way to access child container class via parent container class. or can I add a new class(“second_new”) to “second” class via “first” class.

/* CSS */
.first {
  background-color: red;
}

.first_new {
  background-color: pink;
}

.second {
  background-color: blue;
}

.second_new {
  background-color: purple;
}
<!-- HTML -->
<div class="row">
  <div class="first">
      <h1>This is first class</h1>
      <div class="second"> <!-- I want to change this -->
          <h2>This is Second class</h2>
      </div>
  </div>
  <div class="first">
      <h1>This is first class</h1>
      <div class="second"> <!-- I want to change this -->
          <h2>This is Second class</h2>
      </div>
  </div>
  
</div>
<!-- JAVASCRIPT -->
<script>
    var firstClass = document.getElementsByClassName("first");

    function Mousein() {
        this.classList.add("first_new");

    };
    
    function Mouseout() {
        this.classList.remove("first_new");

    };

    for (var i = 0; i < firstClass.length; i++) {
        firstClass[i].addEventListener('mouseover', Mousein);
        firstClass[i].addEventListener('mouseout', Mouseout);

    }
</script>

Passing multiple params in react-router-dom like reactnavigation

Well, I’ll get to the point with this, and I have a problem passing parameters to the browsing history
For those with experience in reactnavication, you will know how easy it is to pass multiple parameters in the form of an object.

now the problem I have is that the following block

goToChat = (chat) =>
  const { params } = this.props.route;
  const post = params && params.post ? params.post : ""
  const anotherParam = params && params.anotherParams ? params.anotherParams : ""
  ...
  if (chat) {
    this.props.navigation.navigate(CHAT_ROUTE, { chat, param, anotherParam, ... })
  } else {
    ...
  }
}

I have to make it work in a history.push with React-router-dom,
but I haven’t found a way to do it
this is what i improvised

goToChat = (chat) =>
  const { params } = this.props.match;
  const post = params && params.post ? params.post : ""
  const anotherParam = params && params.anotherParams ? params.anotherParams : ""
  ...
  if (chat) {
    this.props.history.push(`${CHAT_ROUTE}/${chat}/, post, anotherParam, ... }`)
  } else {
    ...
  }
}

I’m not sure if I’m close to finding the solution with that attempt

Algorithm implementation to convert propositional formula into conjunctive normal form in JavaScript?

I saw How to convert a propositional formula to conjunctive normal form (CNF)? but it doesn’t go into implementation details. So I was lucky to find this which shows the types:

abstract class Formula { }
class Variable extends Formula { String varname; }
class AndFormula extends Formula { Formula p; Formula q; }  // conjunction
class OrFormula extends Formula { Formula p; Formula q; }  // disjunction
class NotFormula extends Formula { Formula p; } // negation
class ImpliesFormula extends Formula { Formula p; Formula q; } // if-then
class EquivFormula extends Formula { Formula p; Formula q; }
class XorFormula extends Formula { Formula p; Formula q; }

Then it has this helpful (start of a) function CONVERT:

CONVERT(φ):   // returns a CNF formula equivalent to φ

// Any syntactically valid propositional formula φ must fall into
// exactly one of the following 7 cases (that is, it is an instanceof
// one of the 7 subclasses of Formula).

If φ is a variable, then:
  return φ.
  // this is a CNF formula consisting of 1 clause that contains 1 literal

If φ has the form P ^ Q, then:
  CONVERT(P) must have the form P1 ^ P2 ^ ... ^ Pm, and
  CONVERT(Q) must have the form Q1 ^ Q2 ^ ... ^ Qn,
  where all the Pi and Qi are disjunctions of literals.
  So return P1 ^ P2 ^ ... ^ Pm ^ Q1 ^ Q2 ^ ... ^ Qn.

If φ has the form P v Q, then:
  CONVERT(P) must have the form P1 ^ P2 ^ ... ^ Pm, and
  CONVERT(Q) must have the form Q1 ^ Q2 ^ ... ^ Qn,
  where all the Pi and Qi are dijunctions of literals.
  So we need a CNF formula equivalent to
      (P1 ^ P2 ^ ... ^ Pm) v (Q1 ^ Q2 ^ ... ^ Qn).
  So return (P1 v Q1) ^ (P1 v Q2) ^ ... ^ (P1 v Qn)
          ^ (P2 v Q1) ^ (P2 v Q2) ^ ... ^ (P2 v Qn)
            ...
          ^ (Pm v Q1) ^ (Pm v Q2) ^ ... ^ (Pm v Qn)

If φ has the form ~(...), then:
  If φ has the form ~A for some variable A, then return φ.
  If φ has the form ~(~P), then return CONVERT(P).           // double negation
  If φ has the form ~(P ^ Q), then return CONVERT(~P v ~Q).  // de Morgan's Law
  If φ has the form ~(P v Q), then return CONVERT(~P ^ ~Q).  // de Morgan's Law

If φ has the form P -> Q, then:
  Return CONVERT(~P v Q).   // equivalent

If φ has the form P <-> Q, then:
  Return CONVERT((P ^ Q) v (~P ^ ~Q)).

If φ has the form P xor Q, then:
  Return CONVERT((P ^ ~Q) v (~P ^ Q)).

I translated it to JavaScript below, but am stuck on the AND and OR bits. I want to make sure I get this correct too.

The description of my “data model” / data structure is here.

/*
 * Any syntactically valid propositional formula φ must fall into
 * exactly one of the following 7 cases (that is, it is an instanceof
 * one of the 7 subclasses of Formula).
 *
 * @see https://www.cs.jhu.edu/~jason/tutorials/convert-to-CNF.html
 */

function convert(formula) {
  switch (formula.type) {
    case 'variable': return formula
    case 'conjunction': return convertConjunction(formula)
    case 'disjunction': return convertDisjunction(formula)
    case 'negation': return convertNegation(formula)
    case 'conditional': return convertConditional(formula)
    case 'biconditional': return convertBiconditional(formula)
    case 'xor': return convertXOR(formula)
    default:
      throw new Error(`Unknown formula type ${formula.type}.`)
  }
}

function convertConjunction(formula) {
  // CONVERT(P) must have the form P1 ^ P2 ^ ... ^ Pm, and
  // CONVERT(Q) must have the form Q1 ^ Q2 ^ ... ^ Qn,
  // where all the Pi and Qi are disjunctions of literals.
  // So return P1 ^ P2 ^ ... ^ Pm ^ Q1 ^ Q2 ^ ... ^ Qn.
}

function convertDisjunction(formula) {
  // CONVERT(P) must have the form P1 ^ P2 ^ ... ^ Pm, and
  // CONVERT(Q) must have the form Q1 ^ Q2 ^ ... ^ Qn,
  // where all the Pi and Qi are dijunctions of literals.
  // So we need a CNF formula equivalent to
  //    (P1 ^ P2 ^ ... ^ Pm) v (Q1 ^ Q2 ^ ... ^ Qn).
  // So return (P1 v Q1) ^ (P1 v Q2) ^ ... ^ (P1 v Qn)
  //         ^ (P2 v Q1) ^ (P2 v Q2) ^ ... ^ (P2 v Qn)
  //           ...
  //         ^ (Pm v Q1) ^ (Pm v Q2) ^ ... ^ (Pm v Qn)
}

function convertNegation(formula) {
  // If φ has the form ~(...), then:
  //   If φ has the form ~A for some variable A, then return φ.
  //   If φ has the form ~(~P), then return CONVERT(P).           // double negation
  //   If φ has the form ~(P ^ Q), then return CONVERT(~P v ~Q).  // de Morgan's Law
  //   If φ has the form ~(P v Q), then return CONVERT(~P ^ ~Q).  // de Morgan's Law
}

function convertConditional(formula) {
  // Return CONVERT(~P v Q).   // equivalent
  return convert({
    type: 'disjunction',
    base: {
      type: 'negation',
      formula: formula.base,
    },
    head: formula.head
  })
}

function convertBiconditional(formula) {
  // Return CONVERT((P ^ Q) v (~P ^ ~Q)).
  return convert({
    type: 'disjunction',
    base: {
      type: 'conjunction',
      base: formula.base,
      head: formula.head,
    },
    head: {
      type: 'conjunction',
      base: {
        type: 'negation',
        formula: formula.base,
      },
      head: {
        type: 'negation',
        formula: formula.head,
      },
    }
  })
}

function convertXOR(formula) {
  // CONVERT((P ^ ~Q) v (~P ^ Q)).
  return convert({
    type: 'disjunction',
    base: {
      type: 'conjunction',
      base: formula.base,
      head: {
        type: 'negation',
        formula: formula.head,
      },
    },
    head: {
      type: 'conjunction',
      base: {
        type: 'negation',
        formula: formula.base,
      },
      head: formula.head,
    }
  })
}

I have the AND and OR as a pair. So if you write in math like this:

A ∧ B ∧ C ∧ D ∧ E

That would be more like this in code:

A ∧ (B ∧ (C ∧ (D ∧ E)))

But the problem is, we might have arbitrary trees of formulas:

(((A ∧ B) ∧ (C ∧ D)) ∧ (E ∧ F))

Same with the OR. So how would you implement these functions convertDisjunction and convertConjunction, so they can handle that sort of tree data structure?

So what I would do is this:

function convertConjunction(formula) {
  let convertedBase
  if (formula.base.type === 'conjunction') {
    convertedBase = convertConjunction(formula.base)
  }
  let convertedHead
  if (formula.head.type === 'conjunction') {
    convertedHead = convertConjunction(formula.head)
  }
  ???
  // CONVERT(P) must have the form P1 ^ P2 ^ ... ^ Pm, and
  // CONVERT(Q) must have the form Q1 ^ Q2 ^ ... ^ Qn,
  // where all the Pi and Qi are disjunctions of literals.
  // So return P1 ^ P2 ^ ... ^ Pm ^ Q1 ^ Q2 ^ ... ^ Qn.
}

I get lost right at the beginning.

React table – dynamic group header

This is my data

  const data = [
    {
      date: "2021-01-01",
      options: [
        { isFirst: "y", name: "john" },
        { isFirst: "n", name: "Sam" }
      ]
    },
    {
      date: "2021-11-01",
      options: [
        { isFirst: "n", name: "TY" },
        { isFirst: "n", name: "joe" }
      ]
    }
  ];

My current UI:
enter image description here

This is what I want – the group header should be the date
enter image description here

How to do it?

App.js

import "./styles.css";
import React, { useMemo } from "react";

import MyTable from "./MyTable";

export default function App() {
  const data = [
    {
      date: "2021-01-01",
      options: [
        { isFirst: "y", name: "john" },
        { isFirst: "n", name: "Sam" }
      ]
    },
    {
      date: "2021-11-01",
      options: [
        { isFirst: "n", name: "TY" },
        { isFirst: "n", name: "joe" }
      ]
    }
  ];
  const columns = useMemo(
    () => [
      {
        Header: "Name",
        columns: [
          {
            Header: "Name",
            accessor: "name"
          },
          {
            Header: "First One",
            accessor: "isFirst"
          }
        ]
      }
    ],
    []
  );
  return (
    <div className="App">
      {data.map((d) => {
        return <MyTable data={d.options} columns={columns} />;
      })}
    </div>
  );
}

MyTable.js

import React from "react";
import styled from "styled-components";
import { useTable } from "react-table";

const Styles = styled.div`
  padding: 1rem;

  table {
    border-spacing: 0;
    border: 1px solid black;

    tr {
      :last-child {
        td {
          border-bottom: 0;
        }
      }
    }

    th,
    td {
      margin: 0;
      padding: 0.5rem;
      border-bottom: 1px solid black;
      border-right: 1px solid black;

      :last-child {
        border-right: 0;
      }
    }
  }
`;

function DataTable(props) {
  const { data, columns } = props;
  const {
    getTableProps,
    getTableBodyProps,
    headerGroups,
    rows,
    prepareRow
  } = useTable({
    columns,
    data
  });

  return (
    <Styles>
      <table {...getTableProps()}>
        <thead>
          {headerGroups.map((headerGroup) => (
            <tr {...headerGroup.getHeaderGroupProps()}>
              {headerGroup.headers.map((column) => (
                <th {...column.getHeaderProps()}>{column.render("Header")}</th>
              ))}
            </tr>
          ))}
        </thead>
        <tbody {...getTableBodyProps()}>
          {rows.map((row, i) => {
            prepareRow(row);
            return (
              <tr {...row.getRowProps()}>
                {row.cells.map((cell) => {
                  return row.cells.map((cell) => {
                    return (
                      <td {...cell.getCellProps()}>{cell.render("Cell")}</td>
                    );
                  });
                })}
              </tr>
            );
          })}
        </tbody>
      </table>
    </Styles>
  );
}

export default DataTable;

Codesandbox:
https://codesandbox.io/s/xenodochial-tamas-ns9ub

reconstruct an array in JS [duplicate]

How can I reconstruct the array1 to the array2. Could you please help me using map/reduce.
Thank you very much for your helps!

const array1 = [
{Count: 35,
Items: [
{Id:1, Category:'Account', Count:10, class:'A'},
{Id:2, Category:'Account', Count:5, class:'B'},
{Id:3, Category:'Account', Count:20, class:'B'},
]},
{Count: 75,
Items: [
{Id:1, Category:'Logout', Count:25, class:'A'},
{Id:2, Category:'Logout', Count:30, class:'B'},
{Id:3, Category:'Logout', Count:20, class:'C'},
]},
{Count: 85,
Items: [
{Id:1, Category:'Login', Count:10, class:'A'},
{Id:2, Category:'Login', Count:25, class:'B'},
{Id:3, Category:'Login', Count:50, class:'C'},
]}
]

const array2 = [
{name: 'Account', data: [10,5,20]},
{name: 'Logout', data: [25,30,20]},
{name: 'Login', data: [10,25,50]},
]

carousel is not working properly for second and third iteration in react js

I am creating a project in reactjs , where i am rendering carousel in loop, and carousel of first iteration is working perfectly but for other iteration’s it’s not.
can anybody suggest what is the wrong i am doing with the carousel.
this is my codesandbox link :- https://codesandbox.io/s/nice-heyrovsky-8yucf?file=/src/App.js

this is not the actual project so please ignore the empty data and other components.just look at the Prompts and card components.

CSS Float Question (Strange behaviors found)

Dears,

Below is my simple float program and I also attach a picture of the result. My question is: When the width in class “two” is 300px, the div 2 is moved next to the floated div 1, this is also my expectation. However, when i changed the width in class “two” from 300px to 200px, div 2 is kept under div 1, and div 3 is moved to overlap with div 2 (see the attached picture) Why? enter image description here

<html>`
<head>
<style>
.one{
    background: yellow;
    width: 200px;
    height: 50px;
    text-align: center; 
    box-shadow: inset 0 0 10px #000;
    Float: left;
    }

.two {
    background: rgb(55, 0, 255);
    width: 300px;
    height: 50px;
    text-align: center; 
    box-shadow: inset 0 0 10px #000;  
  }

.three {
    background: rgb(255, 0, 76);
    width: 200px;
    height: 50px;
    text-align: center; 
    box-shadow: inset 0 0 10px #000;
   }
 </style>
 </head>
 <body>
    <div class = "one">1</div>
    <div class = "two">2</div>
    <div class = "three">3</div>
 </body>
 </html>

Regex to clean a string and left only digits and the first dot in javascript

I want to replace with a regex any non digit character and the dots after the first one so

“–r43dsd.32.32” would be 43.3232

“–r4.3dsd.32.3.2” would be 4.33232

“–r43dsd.32.3.2” would be 43.3232

I tried this

.replace(/[^0-9.]/g, '')

but I don’t know how to remove the dots with replace and a regex. I read that I should use regex look ahead but I did not understand how to do it.

Is this achievable with only a regex and replace? I also created a function but I want to do it in a more clean way with a regex.

How to pass array of structs as argument on etherscan (tuple[])?

I’m trying to pass the format of array of structs as argument on smart contract write function on etherscan,

This is solidity example:

Info[] public info;

struct Info { 
    address userAddress;
    uint256 amount;   
    bool active; 
} 

enter image description here
Javascript example:

const data = [{0x0000, 10000000000, false},{0x11111, 20000000000, true}]

Can anyone convert this data example to tuple[] and provide it?
Thanks in advance

What is the easiest way to filter an object in javascript? [duplicate]

Yes, I know, there is already a question about how to filter objects in javascript, but look, I’m not asking how to do it, I’m asking about what would be the easiest way, the one which a noob like me could remember.

Before ask I spent a little time and after some tests I came up with theses solutions. They are examples but I cannot think about something better by now:

function queryHandlerOne(query: any) {
  const fields = ["name", "featured", "price", "company", "rating"];
  
  const entries = Object
    .entries(query)
    .filter(([key, _]) => fields.includes(key));

  return Object.fromEntries(entries);  
}
function queryHandlerTwo(query: any) {
  const fields = ["name", "featured", "price", "company", "rating"];

  const entries = Object
    .keys(query)
    .filter(key => fields.includes(key))
    .reduce((acc, key) => {
      acc[key] = query[key];
      return acc;
    }, {} as any);

  return entries;
}
function queryHandlerThree(query: any) {
  const fields = ["name", "featured", "price", "company", "rating"];

  const result = Object
    .keys(query)
    .filter(key => fields.includes(key))
    .map(key => [key, query[key]] as [string, any]);

  return Object.fromEntries(result);
}
function queryHandlerFour(query: any) {
  const fields = ["name", "featured", "price", "company", "rating"];
  const result = {};

  Object
    .keys(query)
    .filter(key => fields.includes(key))
    .forEach(key => Object.assign(result, { [key]: query[key] }));

  return result;
}