Javascript function to Cpp function [closed]

get 2d vector containing all the ways that target string can be constructed by concatenating elements of word bank vector.

I want to convert this function to CPP,
I don’t how this three-line will be in CPP,

const suffixWays = allConstruct(suffix, wordBank);
const targetWays = suffixWays.map(way => [word, ...way]);
result.push(...targetWays);

Whole function:

const allConstruct = (target, wordBank) => {
    if (target === '') return [[]];
    const result = [];
    for (let word of wordBank) {
        if (target.indexOf(word) === 0) {
            const suffix = target.slice(word.length);
            const suffixWays = allConstruct(suffix, wordBank);
            const targetWays = suffixWays.map(way => [word, ...way]);
            result.push(...targetWays);
        }
    }
    return result;
};


console.log(allConstruct('purple',['pur','p','ur','le','purpl']));

output:

[ [ 'pur', 'p', 'le' ], [ 'p', 'ur', 'p', 'le' ] ]

How do I change pseudo-classes in JS?

I have a clock widget on my website and I want the element to have my custom :target animation as soon as it’s activated, without changing the hash.
I know, I could just write my code so the :target animation is played on the element when the widget is shown but I want to manipulate the element to have the :target pseudo-class.
Basically, I want the same effect as using a hash in the URL but without a URL change.
The Firefox DevTools are also based on HTML and JS, right? How do they do it?

Here’s my animation in a snippet:

function initialize() {
  // Here should the code be that applies the :target pseudo-class to div#uhr...
}
document.addEventListener('DOMContentLoaded', initialize)
/* My :target animation */
:target {
    animation-name: hervorhebungWegenHash; 
    animation-duration: 10s; 
    animation-timing-function: linear; 
    animation-fill-mode: both; 
}
@keyframes hervorhebungWegenHash {
    2% {
        color: black;
        background-color: orange;
    }
}
<iframe style="position:fixed;top:0px;left:0px;width:120px;height:120px;border:1px solid #4682b4;border-radius:50%;pointer-events:none;overflow:hidden;" id="uhr" src="https://www.lampe2020.de/widgets/uhr">&nbsp;</iframe>

<a href="https://stackoverflow.com/a/46262124/17865928" title="copied 2022-05-26" style="position:absolute;top:125px">This clock widget is also from SO.</a>

To see the animation applied, go to my website, type “uhr” into the page (no textarea, just on the page). Otherwise you can check it by applying #page to my main page. Then the whole block in the middle should be orange and fade out to blue over the course of ~9 seconds.

How can I override the styling of an MUI checkbox which I have not written?

I am using Material-Table to display data. I am using the columnsButton property in table options to allow users to hide columns. I want to override the checkboxes that appear to align with my color scheme.

The columnsButton property adds this small icon next to the search bar. Clicking it opens the popover seen below. Unchecking the options here will hide columns from the table. I do not have to write any extra code for this popover. It is a native feature of Material-Table.

I want to change the border color and checked color of these checkboxes to match my color theme.

enter image description here

Here is my table:

            <MaterialTable
                title=""
                data={intakes.intakes}
                columns={columns}
                icons={tableIcons}
                options={{
                    columnsButton: true
                }}
            />

enter image description here

JSX without react. Just pure es6 and HTML

Good day fellow devs! Is it possible to return a jsx format from a function without using react? My project is just pure Es6 and HTML. Here’s what I want to do, I want to create a separate files for functions and HTML then call the HTML format files in the functions.

For example, here’s my main.js:

import renderHTML from './display/render.js';
import createElement from './functions/createElement.js';

var popup = document.getElementById('popup-container');

const HTML = `${renderHTML}`;

const Fragment = createElement(HTML);
popup.appendChild(Fragment);

Then in my renderHTML file where it’s jsx format, here’s the content:

export default function renderHTML() {
 return (
  <h1>I am the content! Rendered successfully!</h1>
 )
}

There, hope that made sense lol.. But yeah, the output of that is either its code or object. Any help or advice if I’m doing it wrong is much appreciated. Thank you so much and have a nice day ahead!

How to put a file in my data and posted with javascript

pleas
I have my following code:

let data = {
    input: {
      amount: 100,
      identity_card: document.forms["form"]["file"].files[0],
    }
}

But it does not work.
I would like my identity_card attribute to be a file.
I tried every possible way, but without success.
I even tried with the FormData but without success

Getting “Invalid channel” error with Node-OPCUA when connecting with user/pass/encryption

I am trying to connect to a server with node-opcua, but having a bit of trouble.

Connecting to the same server with the Prosys OPC UA Browser software works just fine.

const client = OPCUAClient.create({
    endpointMustExist: false,
    securityMode: MessageSecurityMode.SignAndEncrypt,
    securityPolicy: SecurityPolicy.Basic256Sha256
});

await client.connect(endpointUrl);

session = await client.createSession({
        userName: data.userName,
        password: data.password,

    },
    function(err) {
        console.log(err)
    }
);

It connects, but I am getting the error: ‘Error: Invalid channel’

What does this mean?

As far as I understand, node-opcua should automatically handle self signed certificate[1], (if this is an issue at all)?

[Note 1]
Ref: How to trust a self-signed server certificate with the node-opcua client

[Note 2]
For what it’s worth, when I connected with Prosys OPC UA Browser, teh software asked me to automatically generate certificate, which I accepted. I tried to provide these generated files to node-opcua code with the parameters certificateFile and privateKeyFile. It found the files, but would not accept them (Uncaught (in promise) Error: Invalid position : buf.length=0 pos =0).

How to extract elements from array nested inside json array [duplicate]

I have json array of objects stored in a file in which each json object has an array property field.I want to get those array data.I am able to get that data but its in individual array format.
I want to get data in properly formatted in single json array format.I want to get topping field from each json object.

Below is my code:

cake.js

const nam = [
{
    "id": "0001",
    "type": "donut",
    "name": "Cake",
    "ppu": 0.55,
    "batters":
        {
            "batter":
                [
                    { "id": "1001", "type": "Regular" },
                    { "id": "1002", "type": "Chocolate" },
                    { "id": "1003", "type": "Blueberry" },
                    { "id": "1004", "type": "Devil's Food" }
                ]
        },
    "topping":
        [
            { "id": "5001", "type": "None" },
            { "id": "5002", "type": "Glazed" },
            { "id": "5005", "type": "Sugar" },
            { "id": "5007", "type": "Powdered Sugar" },
            { "id": "5006", "type": "Chocolate with Sprinkles" },
            { "id": "5003", "type": "Chocolate" },
            { "id": "5004", "type": "Maple" }
        ]
},
{
    "id": "0002",
    "type": "donut",
    "name": "Raised",
    "ppu": 0.55,
    "batters":
        {
            "batter":
                [
                    { "id": "1001", "type": "Regular" }
                ]
        },
    "topping":
        [
            { "id": "5001", "type": "None" },
            { "id": "5002", "type": "Glazed" },
            { "id": "5005", "type": "Sugar" },
            { "id": "5003", "type": "Chocolate" },
            { "id": "5004", "type": "Maple" }
        ]
},
{
    "id": "0003",
    "type": "donut",
    "name": "Old Fashioned",
    "ppu": 0.55,
    "batters":
        {
            "batter":
                [
                    { "id": "1001", "type": "Regular" },
                    { "id": "1002", "type": "Chocolate" }
                ]
        },
    "topping":
        [
            { "id": "5001", "type": "None" },
            { "id": "5002", "type": "Glazed" },
            { "id": "5003", "type": "Chocolate" },
            { "id": "5004", "type": "Maple" }
        ]
  }
];

module.exports = nam;  

server.js

const express = require('express');
const nam = require('./cake');

const app = express();

const port = process.env.PORT || 3000;

app.get('/',(req,res) => {

const top = nam.map((data) => {

    return data.topping;
});
    res.status(200).send(top);
});

app.get('/home',(req,res) => {
  res.send("Hello home");
});

app.listen(port,() => {
  console.log(`Server is running on ${port} port`);
});

OUTPUT

[
 [
  {
   "id": "5001",
   "type": "None"
  },
  {
   "id": "5002",
   "type": "Glazed"
  },
  {
   "id": "5005",
   "type": "Sugar"
  },
  {
   "id": "5007",
   "type": "Powdered Sugar"
  },
  {
   "id": "5006",
   "type": "Chocolate with Sprinkles"
  },
  {
   "id": "5003",
   "type": "Chocolate"
  },
  {
   "id": "5004",
   "type": "Maple"
  }
 ],
[
  {
   "id": "5001",
   "type": "None"
  },
  {
   "id": "5002",
   "type": "Glazed"
  },
  {
   "id": "5005",
   "type": "Sugar"
  },
  {
   "id": "5003",
   "type": "Chocolate"
  },
  {
   "id": "5004",
   "type": "Maple"
  }
 ],
[
 {
  "id": "5001",
  "type": "None"
 },
 {
  "id": "5002",
  "type": "Glazed"
 },
 {
  "id": "5003",
  "type": "Chocolate"
 },
 {
  "id": "5004",
  "type": "Maple"
 }
  ]
]

I am getting 1 array having 3 arrays which are containing json objects each.I want to get data somewhat like in below format from all the three arrays in one single array of objects:

[
 {
   "id": "5001",
   "type": "None"
 },
 {
   "id": "5002",
   "type": "Glazed"
 },
 .
 .
 .,
 {
   "id": "5005",
   "type": "maple"
 }
]

Someone please help me out.Any help would be appreciated.

How to remove inert attribute in the page using typescript [duplicate]

In my page, inert tag is available, due to this unable to click, focus on the page. Kindly suggest how to remove inert tag while click on some specific functionfrom the page. I tried with removeAttribute, but getting error

document.getElementsByTagName('div').removeAttribute('inert');
<div>
  <label for="button1">Button 1</label>
  <button id="button1">I am not inert</button>
</div>
<div inert>
  <label for="button2">Button 2</label>
  <button id="button2">I am inert</button>
</div>

Dimensions of an image should be preferably specified in % instead of a pure number. Comment. (multiple answers correct) [closed]

Dimensions of an image should be preferably specified in % instead of a pure number. Comment. (multiple answers correct)

This problem may have one or more correct answers

a) It does not matter since the same thing can be achieved using both.
b) % adjusts image size according to the screen resolution, unlike a pure number.
c) Image dimensions specified using a pure number may appear small or large on different
screens with different dimensions.
d) % is not preferable over a pure number because a pure number accurately specifies the
image dimensions.

Wrong Answer, Attempt Again

Knockout js. Trying to use If inside foreach

I am trying to do a string search in my foreach statement, if x inc (Overseer) make the text blue, else, leave as normal. however, when I run this, none of the names show up.

                                <!-- ko foreach: Staffs -->
                                <!-- ko if: $index().contains('(Overseer)')-->
                                <div class="col-sm-11 col-sm-offset-1" style="color: blue"><span data-bind="text: Text"></span></div>
                                <!-- /ko -->
                                <!-- ko ifnot: $index().contains('(Overseer)')-->
                                <div class="col-sm-11 col-sm-offset-1"><span data-bind="text: Text"></span></div>
                                <!-- /ko -->
                                <!-- /ko -->

next js form working fine in dev mode but refreshing the page in build

I have created a login form in next.js the form is working fine in dev mode(npm run dev) buut when i create its build using (npm run build) it refresh the page and add ? at the end of the url it should be calling the handleLogin function

package.json:-

"scripts": {
"dev": "next dev",
"build": "next build",
"export": "next build",
"start": "next start",
"lint": "next lint"
}

Login form:-

<Form onSubmit={handleLogin}>
<FormGroup className="formcntainer">
<Label><FaUserAlt/></Label>
<Input type="text" placeholder="Your Email" onChange={handleChange("email")}/>
</FormGroup>
<FormGroup className="formcntainer">
<Label><AiFillLock/></Label>
<Input type="password" placeholder="Password" onChange={handleChange("password")}/>
</FormGroup>
<FormGroup>
<Input type="submit" value="Log In" />
</FormGroup>                  
</Form>

handle submit function:-

const handleLogin = (event) =>{
event.preventDefault();
console.log("in form");
}

When adding number and string type input, output is giving concatenation but string and number giving strange output in javascript?

I know that addition of number and string concatenates the two inputs in javascript which is completely understandable but string and number addition giving strange output. Please somebody let me know why this is happening.

calculate.js

let fs = require("fs");
let data = fs.readFileSync(0, 'utf-8');
let idx = 0;
data = data.split("n");

function readLine() {
    idx++;
    return data[idx - 1];
}

let unitCost = readLine();
console.log(unitCost);
console.log(typeof(unitCost))

let GSTpcnt = readLine();
console.log(GSTpcnt);
console.log(typeof(GSTpcnt));


let tax = GSTpcnt / 100 * unitCost; 
console.log(tax);
console.log(typeof(tax));


// let finalCost = tax + unitCost; // number + string ==> 18100
let finalCost = unitCost + tax; //string + number ==>  180

console.log(finalCost);
console.log(typeof(finalCost));

input.txt:

100
18

How do I filter out JSON with certain values? [closed]

Hi I’m pretty new to JavaScript with want to experiment with some JSON, I was trying to figure out how to filter all json groups with the status On so I could put them into separate arrays. But I tried something like this and it didn’t detect the ones with On, maybe some of you know what I’m doing wrong? This is just for experimenting.

var myMap = [{
    id: 1,
    name: "World 1",
    status: "On"
  },
  {
    id: 2,
    name: "World 2",
    status: "Off"
  },
  {
    id: 3,
    name: "World 3",
    status: "On"
  }
]

var result = data.filter(x => x.status === "On");
console.log(result);

Javascript code to find the Total number of values between different ranges and also add single numbers

I have few lists like this

a = [ 2, 47-54, 68-69, 120-121, 318, 320, 342, 364-366, 414-422, 503-505, 513-514, 529, 554, 586, 690, 775, 913, 1018, 1117, 1159, 1183, 1218-1219, 1379, 1478, 1491, 1497, 1510, 1562, 1601, 1664, 1673, 1686, 1692, 1710, 1759-1765, 1862-1881, 1951-1962, 1992, 2020 ]

b = [ 18, 28, 34-35, 58-84, 110-137, 139-191, 193-272 ]
value of b = 188

Trying to get a simple javascript code to get the total number of values between different ranges and also add single numbers as I have mentioned for the value of b.