how to remove a few characters from a sentece

this is what i mean:

{input_value: hello,world}

func delete (target, wordstodelete): // delete wordstodelete from target

{new_input_value = delete “,world” from input_value}

so this is my file code:

<input id=“extension” type="file”>
<script>
Let e = document.getelementbyid(“extension”).value;
if(e.includes(“.atkp”)) {

}else{
alert(“this file can’t be accessed since it doesn’t have the extention ‘.atpk’.”)
}
</script>

i asked google and many other websites like w3schools. i found nothing useful except the substr() but it uses numbers. i want a function something like this: let e-edited = e.substr(".atkr"), instead does this let e-edited = e.substr(1, 3).
i have nothing to start with. if i have to use the substr() method, then i have to make sure that the length is 10 or 8 characters and a name like: gghh.atkp or exampl.atkp.

JS: try/catch assertion testing is failing

not sure what I am doing wrong but it seems fairly simple in my head. I have a class that creates a new Session class inside it. If the MainClass ‘s foo function throws, session‘s deleteEmpty function is called.

I am trying in my test to ensure that thrown has a value and that the deleteEmpty is called. When I have the thrown assertion itself, it passes. When I add the assertion to check deleteEmpty is called, it fails but the console has no output as to why.

MainClass

const token = "12345";
const data = { /// };

const session = new Session(token, data);

function foo() {

    try {
       //

    } catch(error) {
     
       this.session.deleteEmpty()
    }
}

testFile

const sessionMock = Sinon.createStubInstance(Session)
let thrown: Error | undefined = undefined;

sandbox.stub(MainClass, 'foo').throws();

try {
    await MainClass.foo();
} catch(error) {
    thrown = error;
}

expect(sessionMock.deleteAsset).calledOnce;
expect(thrown).to.not.be.undefined;

Make Iframe accessible only through my app and block direct access through browser

Is there a way to let an iframe application be acceessible only within my web app and not directly from the browser? So even if somehow the user gets a hold of the iframe application url, they are not able to access it. I have searched some older answers but haven’t really found a viable solution.

FYI, I am hosting both the applications myself and therefore am in control of their networking, ports or domains etc. So I am open to options like using docker containers, nginx or anything else. The only thing I want to avoid the touch the html/javascript content of the iframe application due to multiple issues. I am open to making changes to the parent application though.

Javascript – indexed html UL>LI – how to insert new LI between uncertain values?

Let’s imagine: we have message list, represented by html ul > li items.
Each item has index – Unix timestamp with milliseconds.

<ul>
 <li ts="1657744925386">Item 1</li>
 <li ts="1657744941061">Item 2</li>
 <li ts="1657744953364">Item 3</li>
 <li ts="1657744964372">Item 4</li>
 <li ts="1657744973219">Item 5</li>
 <li ts="1657744978450">Item 6</li>
</ul>

Then we have to insert another item, with ts=1657744950123.
It should be after Item 3.

Is there an efficient way to calculate the new position in the list so that jQuery can insert the new element (because it requires a reference element relative to which will be inserted after or before the new element), given that there can be a lot of messages on the page and we don’t have possibility to walk through all of them every time, making comparisons?

Why am I getting as TS(1005) error on a line of code (below)?

progress-bar2 = document.getElementById("progressbarfull");

I am fairly new to coding and the error is to do with the ‘=’ symbol but I’m not sure why..

I have changed the name of the class to something with out the hyphen and it is not that and I’m using progress-bar2 in my HTML and CSS I am also using other = document.getElementbyID/getElementbyClassName

I hope this make sense and if someone could help I’d really appreciate it.

How to build Apache Arrow Schema with a Map field?

I am using Apache Arrow JS and I want to create a schema that has a field of type Map having a key with type as String (Utf8 in Arrow) and value as a custom type which is a struct of many different types. I was able to create struct as follows:

const temp = new arrow.Struct([arrow.Field.new({name: "struct field 1", type: "new arrow.Int()"}), arrow.Field.new({name: "struct field 2", type: "new arrow.Bool()"})])

I have tried using arrow.MapBuilder<new arrow.Utf8(), temp> but this gives me an error Unexpected ",". I have also tried the following:

new arrow.Map_({key: new arrow.Utf8(), value: temp, keysSorted: false}) 

I get the following error:

if (type.children && type.children.length > 0) {
                 ^

TypeError: Cannot read property 'children' of undefined

I tried looking up for how to create a schema with a map field type but I have not been able to find any useful information so far. The API documentation also does not provide the usage for any of the Arrow Fields. Any help would be appreciated.

I am referring to the following documentation for Apache Arrow JS

SVGs not rendering after destructuring in react

When I run my React application, the background renders without the foreground SVGs.
Only the ModernBG and AncientBG components render. These are the background images of the ancient and modern world map.

There should be 4 svgs (Modern Europe, Modern China, Ancient China, Ancient Europe) rendered overtop of the background components.
See my App.js code below and the repo link here: https://github.com/thePurpleCloud7/map-react-app-v1.0/blob/master/src/App.js
Thank you in advance! Any help would be greatly appreciated.


App.js:

import "./index.css";
import MEurope from "./components/MEurope";
import AChina from "./components/AChina";
import MChina from "./components/MChina";
import AEurope from "./components/AEurope";
import ModernBG from "./components/ModernBG";
import AncientBG from "./components/AncientBG";
const { useState } = require("react");



export default function App() {
const [selectedCountry, setSelectedCountry] = useState("");
const [hoveredCountry, setHoveredCountry] = useState("");

const modernCountries = [
    { name: "europe", Component: MEurope, x: 0, y: 0 },
    { name: "china", Component: MChina, x: 100, y: 100 },
];

const ancientCountries = [
    { name: "europe", Component: AEurope, x: 300, y: 300 },
    { name: "china", Component: AChina, x: 500, y: 500 },
];

return (
    <>
     <ModernBG>
      { modernCountries.map((Component, x,y, name) => {

            return (
                    <Component
                        x={x}
                        y={y}
                        country={name}
                        selectedCountry={selectedCountry}
                        hoveredCountry={hoveredCountry}
                        onClick={() => setSelectedCountry(name)}
                        onMouseEnter={() => {
                            console.log("ENTERModern");
                            setHoveredCountry(name);
                        }}
                        onMouseExit={() => setHoveredCountry("")}
                    /> 
            );}
             )}
                    
    </ModernBG>

    <AncientBG>
        {ancientCountries.map((Component, x,y, name) => {
             return (
                <Component
                    x={x}
                    y={y}
                    country={name}
                    selectedCountry={selectedCountry}
                    hoveredCountry={hoveredCountry}
                    onClick={() => setSelectedCountry(name)}
                    onMouseEnter={() => {
                        console.log("ENTERAncient");
                        setHoveredCountry(name);
                    }}
                    onMouseExit={() => setHoveredCountry("")}
                /> 
        );
        })}
    </AncientBG>
    </>
);

}

Selecting random ROUND number without being non-even distribution

So I want to make a number selector in JS that select a ROUND number between 1 and 100. Like selecting a winning ticket for example.

I found out I could use a function and then Math.round, like this

    function sort(min,max) {
    return Math.round(Math.randon() * (max - min) + min)
}
console.log(sort(1,100))

But then I readed Math.round will make a non-even distribution, with max and min values less likely to roll than the others.

So how can I solve this one? Getting a ROUND number between 1 and 100 with even distribution?

Grouping arrays and 2D arrays into a single 2D array with the same length for all

Since home_team and/or away_team can be empty but they must be 2D arrays with index [0] and [1] and I need to join them all (having an always empty index between home_team and away_team), I did it as follows:

function if_empty(the_list) {
  if (the_list.length > 0) {
    return the_list
  } else {
    return [[null,null]]
  }
}

function group_arrays() {
  const menu = [
    ['abcd'],
    ['1234']
  ];

  const home_team = [];
  const ht = if_empty(home_team);

  const away_team = [
    ['val1', '0001'],
    ['val2', '0002'],
    ['val3', '0003']
  ];
  const at = if_empty(away_team);

  const collection = [menu, ht, [], at];
  const output = Array(Math.max(...collection.map((a) => a.length)))
    .fill()
    .map((_, i) => collection.flatMap((a) => a[i]));

  Logger.log(output)
}

But as you can see, index 0 has 6 values and the others have only 5:

[
  [abcd, null, null, null, val1, 0001],
  [1234, null, null, val2, 0002],
  [null, null, null, val3, 0003]
]

But I need that regardless of where values are missing, they must always be aligned with 6 values each:

[
  [abcd, null, null, null, val1, 0001],
  [1234, null, null, null, val2, 0002],
  [null, null, null, null, val3, 0003]
]

What should I readjust in my code to get around this problem?

I notice that the cause of this is in the 2D arrays that when they don’t have values, they only generate 1 empty value instead of 2 empty values as expected by me.

Comparing dates yield inconsistent results in JavaScript

Why does case A work, but not case B?

Case A

const today = new Date();
//> Wed Jul 13 2022 14:19:30 GMT-0400 (Eastern Daylight Time)

const july13th = new Date('7/13/2022');
//> Wed Jul 13 2022 00:00:00 GMT-0400 (Eastern Daylight Time)

today > new Date('7/13/2022')
//> true

today < new Date('7/13/2022')
//> false

This all makes sense.

Case B

const setDateBackOneYear = function(date) {
    lastYear = date.getFullYear() - 1;
    month    = date.getMonth() + 1; // as January === 0
    dayNo    = date.getDate();
    return new Date(`${lastYear}/${month}/${dayNo}`)
}

setDateBackOneYear(july13th)
//> Tue Jul 13 2021 00:00:00 GMT-0400 (Eastern Daylight Time)

new Date('7/13/2021')
//> Tue Jul 13 2021 00:00:00 GMT-0400 (Eastern Daylight Time)

setDateBackOneYear(july13th) > new Date('7/13/2021')
//> false

setDateBackOneYear(july13th) < new Date('7/13/2021')
//> false

Even

setDateBackOneYear(july13th) > setDateBackOneYear(july13th) 
//> false

setDateBackOneYear(july13th) > setDateBackOneYear(july13th) 
//> false

but this works again:

const lastYearsJuly13th = setDateBackOneYear(july13th);
lastYearsJuly13th.setHours("7");
//> Tue Jul 13 2021 07:00:00 GMT-0400 (Eastern Daylight Time)

setDateBackOneYear(july13th) < lastYearsJuly13th
//> true

Probably missing something very basic.

Remove duplicates from array and remove the same index from another array

I have 2 arrays, one array contains prices and the other one dates. I want to remove all duplicate prices , and I want to remove the same indexes of the date array.
How would one do this?

An example of my arrays:

['2022-06-27', '2022-07-02', '2022-07-03', '2022-07-04', '2022-07-05']
 [3.79, 4.29, 4.29, 4.29, 4.36]

end result needed:

 ['2022-06-27', '2022-07-02', '2022-07-05']
 [3.79, 4.29, 4.36]

React: error Module ‘”react-router-dom”‘ has no exported member ‘useNavigate’

I am trying to import useNavigate to use it as described in the top response: react button onClick redirect page

import { useNavigate } from "react-router-dom";

However, I get this error:

export 'useNavigate' (imported as 'useNavigate') was not found in 'react-router-dom' (possible exports: BrowserRouter, HashRouter, Link, MemoryRouter, NavLink, Prompt, Redirect, Route, Router, StaticRouter, Switch, generatePath, matchPath, useHistory, useLocation, useParams, useRouteMatch, withRouter)

Unlike this post, export ‘useNavigation’ (imported as ‘useNavigation’) was not found in ‘react-router-dom’, I spell useNavigate correctly, so what could be other reasons as to why there is this error?

Adding a custom navbar to an existing site

I work for a company that uses multiple tools/sites and am trying to figure out a way to consolidate them so they “appear” under one umbrella, one way I’m trying is get a custom web page built which links all of these various websites, i’m using HTML/JS and basically i’ve tried creating a new web page for each site with my templated nav bar in the header. The issue i’m running into is i usually get an error like “ERR_BLOCKED_BY_RESPONSE”. Mind you some of these sites require additional log in through OKTA like JIRA or Monday, so there might a security issue?

Also while i’m writing this i’ve also just considered if someone clicks something in those pages and navigates to another page within the site, they’ll likely lose the navbar.

Has anyone done something like this before? or is there a better solution?

Sequelize Association is generating an integer foreign key, but I want a string

I am using Sequelize for my database interfacing and I have run into a problem.
I am building a project revolving around restaurants and in the database I am trying to add restaurant specific menus. So there is one restaurant associated to many menus. Here is my code for creating all my associations.

const Company = require("./Company");
const Employee = require("./Employee");
const Restaurant = require("./Restaurant");
const CompMenu = require("./Comp-menu");
const RestMenu = require("./Rest-menu");

Company.hasMany(Employee, { foreignKey: 'company_id' });
Employee.belongsTo(Company, { foreignKey: 'company_id' });

Company.hasMany(Restaurant, { foreignKey: 'company_id' });
Restaurant.belongsTo(Company, { foreignKey: 'company_id' });

Company.hasMany(CompMenu, { foreignKey: 'company_id' });
CompMenu.belongsTo(Company, { foreignKey: 'company_id' });

// Restaurant - Restaurant Menu Associations Here
Restaurant.hasMany(RestMenu, { foreignKey: 'restaurant_id'});
RestMenu.belongsTo(Restaurant, { foreignKey: 'restaurant_id'});

Company.hasMany(RestMenu, { foreignKey: 'company_id' });
RestMenu.belongsTo(Company, { foreignKey: 'company_id' });

Restaurant.belongsToMany(Employee, { through: "Restaurant_Employees"});
Employee.belongsToMany(Restaurant, { through: "Restaurant_Employees"});

module.exports={
    Company,
    Employee,
    Restaurant,
    CompMenu,
    RestMenu,
};

But the type of the foreignKey being generated for the restaurant-restaurant menu association is Integer. So when I go to create a restaurant menu (RestMenu), it says there is an error because the restaurant id I try to use create the menu is a string. Here are my models for my restaurant menus and for my restaurants.

Restaurant Model:

const { Model, DataTypes } = require('sequelize');
const sequelize = require("../config/connection");

class Restaurant extends Model {}

Restaurant.init(
    {
        restaurant_id: {
            type: DataTypes.STRING,
            allowNull: false,
        },
        name: {
            type: DataTypes.STRING,
            allowNull: false,
        },
        location: {
            type: DataTypes.STRING,
            allowNull: false,
        }
    },
    {
        sequelize,
    }
)

module.exports = Restaurant;

Restaurant Menu Model:

const { Model, DataTypes } = require('sequelize');
const sequelize = require("../config/connection");

class RestMenu extends Model {}

RestMenu.init(
    {
        menu_id: {
            type: DataTypes.STRING,
            allowNull: false,
        },
        name: {
            type: DataTypes.STRING,
            allowNull: false,
        }
    },
    {
        sequelize,
    }
)

module.exports = RestMenu;

So basically my problem is that I can’t add RestMenus to my database because the database is set up to hold an integer for the restaurant_id column for RestMenus but I can’t figure out why it’s not a string like the rest of my associations are.

Also I have the sync force true on my server file so it is generating a new database when I restart the server.

sequelize.sync({ force: true }).then(function() {
    httpServer.listen(PORT, function() {
    console.log('App listening on PORT ' + PORT);
    });
});

Am I doing something unintentionally that is setting the foreign key to an integer? Or is there someway to manually override the foreign key type to a string?

Is it possible to get the lastModified date of a file hosted on the server?

With the code below I’m able to read, and log to the console, the contents of a file (myfile.txt) hosted on-line on the same folder/server as the HTML page with such code.

<!DOCTYPE html>
<html>

<script>

async function doIt()
{
  let response = await fetch("myfile.txt", {cache: "no-store"});
  let contents = await response.text();
  console.log(contents);
}
    doIt();

</script>

</body>
</html>

My problem is that instead of the file contents I want to log the date/time when such file (myfile.txt) was last modified and I can’t find the way to do it.

What am I missing? Would it be possible? How?

Many thanks in advance for any help!