Sort array and object by values from JSON in js

Develop a simple application for sorting and selecting data according to predefined criteria
rules The application must be able to work with a list of arbitrary JSON object
structures, select objects corresponding to keys with corresponding values, and also
sort objects by value using the natural sort order.
I tried different ways like filter(), map(), sort, and many others…
I am a full noob….
example

{"data":[ {"name": "Peter", "email": "[email protected]"},
{"name": "Peter", "email": "[email protected]"},
{"name": "Marge", "email": "[email protected]"}]}

income values:

{"condition": {"include": [{"name": "Peter"}], "sortBy": ["email"]}}// returns only with name peter

and
"condition": {"exclude": [{"name":"Marge"}], "sort_by": ["email"]}} // returns other

Actually, I want to understand what and how so if you can explain it will be great. thanks a lot)

`const data = [
{"name": "John", "email": "[email protected]"},

{"name": "John", "email": "[email protected]"},

{"name": "Jane", "email": "[email protected]"},

{"name": "Margaret", "email": "[email protected]"} ];

function fullSort (arr, sort_by){
const propComparator = (sort_by) =>
(a, b) => a[sort_by] === b[sort_by] ? 0 : a[sort_by] < b[sort_by] ? -1 : 1; /// working

console.log("by parametr", data);

function arrayRemove(arr, sort_by) { 

return data.filter(function(ele){  ///working
    return ele.name != sort_by; 
});

}
console.log(arrayRemove(arr, sort_by))
data.sort(propComparator("sort_by"))
}
return fullSort(data, "John");`

React vs NextJs 13 for file manipulation web app? [closed]

I want to develop an application similar to canva.com in which users can generate files (mainly spreadsheets via google’s API), easily modify them and then download them. All of this features will be, naturally, server-side. But since the latest NextJs version already have server side components (altough in beta) and provides an pretty good route for API handling, I’m wondering if going for a Next.js only approach would be wise? If not, I would like to hear your suggestions. Would it be better to go with Node for the backend and plain React for the frontend?

Center div by specific item

Is it possible to center not the whole child-container div but by an specific item. The content of the first p and last p have different heights and can change dynamically.

.container {
  display:flex;
  align-items: center;
  height: 300px;
  background-color: red;
}

.child-container {
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  background-color: purple;
}

.big{
  line-height:40px;
}

.bigger{
  line-height:80px;
}
<div class="container">
<div class="child-container">
  <p class="big">Lorem ipsum</p>
  <p>Center this</p>
  <p class="bigger">Lorem ipsum</p>
</div>
</div>

Server.close() not stoping

Below is a simple code which I wrote :-


var http = require('http');
var server = http.createServer(function (req,res) {
  res.end("Hello World") 
})

server.listen(5000);



setTimeout(() => {server.close() } ,5000);

The behaviour which I expected was that server should stay on for 5 seconds and then closes. But rather what is happening is that server stays on indefinitely and we can do anything, however when we leave server idle for 5 seconds, after that if we reload or do anything then the timer of 5 seconds starts and after that server closes.
Means from 0 to n seconds I kept on working, then left idle for 5 seconds, on 25th second I reloaded again and then on 30th second the server is closing.

Why is it happening like that. Basically settimeout will move to call queue after 5 seconds and then it should be moved to call stack by event loop and close the server as soon as it goes idle.
Why is it behaving differently ?

I expected that the server shall close after 5 seconds but it is not happening so.

jQuery: How to differ multiple same buttons and pass parameter?

I try to move this working solution to jQuery.

<table>
    <tr th:each="l : ${lst}">
        <td>
            <input type="button" th:onclick="foo ([[${l}]])"/>
        </td>
    </tr>
</table>

....

function foo (x)
{
}

How can I do this the jQuery way? Is it a good idea to do so?

I tried this but I do not know how to get the parameter ${l} into the function also how to differ the differnt buttons.

<table>
    <tr th:each="l : ${lst}">
        <td>
            <input type="button" id="mybutton"/>
        </td>
    </tr>
</table>

...

$("#mybutton").click (function ()
{
});

Vue.js How to pass data from computed properties using props from parent to child

I am trying to use computed property booksList from App.vue to make a list using html (in Booklist.vue). I also need to make it exact size which is windowSize and i need to display book.title and book.author of each book in booklist in this html list. Here are the things i used trying to pass the data to child (which is Booklist.vue)in template of parent App.vue
props in App.vue
my computed looks like this in App.vue
and in child it looks like this (i did not do much here but im just trying to figure out how to use data from parent Booklist.vue
So my question is how to put data from computed property in App.vue in a list in Booklist.vue

I didnt use git for this project so if you need to see more let me know

splitting value from a datalist classic asp

function ChosenValue(){

document.cpmat.aqty.value=(document.cpmat.SNSUPDESCRIPTION.value)
}

The above function is used to populate another text box from a data list using clasic asp and same is working fine.

However this function returns both the SN and Description and i want to split the SN and Description.

When I use the split no value is being return.

Here is the coding which i’m using to split

document.cpmat.aqty.value=Split((document.cpmat.SNSUPDESCRIPTION.value),”—Code:”)

I’ve also tried to assign the selected data from the datalist to a variable to split it later and this also is not working
VAR_SN=document.cpmat.SNSUPDESCRIPTION.value

Child element fixed position and 100% width of parrent

I have child element sidebar and i’d like to set him 100% width of parent element. That works without fixed position. But also i need fixed position for “collapse/expand” function.

.non-active{left: -250px;} Parent element is maximum 250px of width;

Javascript collapse/expand

   $(".close-btn").click(function () {
      $(".side-bar").addClass("non-active");
      $(".menu-btn").css("visibility", "visible");
    });

    $(".menu-btn").click(function () {
      $(".side-bar").removeClass("non-active");
      $(".menu-btn").css("visibility", "hidden");
    });

Sidebar.html

<div class="menu-btn">
  <i class="fas fa-bars vertical"></i>
</div>
  <div class="side-bar">
    <div class="close-btn">
      <i class="fas fa-times vertical"></i>
    </div>
    <h1>Doučování</h1>
    <div class="menu">
      <div class="item">
        <a class="sub-btn">
          Matice
          <i class="fas fa-angle-right dropdown"></i>
        </a>
        <div class="sub-menu">
          <a
            href="/pages/matice/zakladni-operace.html"
            id="matice/zakladni-operace"
            onClick="reply_click(this.id)"
            class="sub-item">
            Základní operace
          </a>
          <a
            href="/pages/matice/hodnosti.html"
            id="matice/hodnosti"
            onClick="reply_click(this.id)"
            class="sub-item">
            Hodnost
          </a>
        </div>
      </div>
    </div>
  </div>

Sidebar.css

.side-bar {
  background: #1b1a1b;
  backdrop-filter: blur(15px);
  width: 100%;
  height: 100vh;
  position: fixed;
  top: 0;
  z-index: 50;
  overflow-y: auto;
  transition: 0.6s ease;
  transition-property: left;
}

Enlarge images by clicking (JQuery)

I want a second class to be added to each image by clicking on it and the image will be the size defined in the second class:

HTML:

<div class="photo_main">

        <img src="a.jpg" alt="">

</div>

CSS:

.photo_main {
    text-align: center;
    margin: 5rem auto 2rem;

    cursor: pointer;
}

.photo_main > img {
    width: 350px;
    height: 250px;
}

.size_img {
    width: 850px !important;
    height: 550px !important;
}

script:

   $(document).ready(function () {
    $('.photo_main').click(function () {
        $(this).addClass('size_img');

    }, function () {
        $(this).removeClass('size_img');
    });
});

get the index of two elements and manipulate the array accordingly

I build an array with the following code:

var intestColonne = [];
$('.tbi').find('tr:first th').each(function(){
    intestColonne.push(($(this).children('select').val()));
});
//intestColonne=intestColonne.pop();  //if this row is parsed the array becomes undefined

Now I want to check if there are multiple entries of a specific value in the array:

if(intestColonne.filter(x => x === "importo").length>1){
    //check the index of each "importo" element
    //store it into variables
    //remove all the other "importo" leaving only the first (lowest index)
}

I am stuck at the first step since I haven’t found a specific function that may return all the indexes of the “importo” value.

indexOf will return the first index, lastIndexOf will return the last. Using indexOf I can specify where to start looking from but this will hardly satisfy my goal.

Isn’t there another type of search I can use?

jquery inside express POST / GET handlers: possible?

I wrote this small Express server to get data from an HTML form and query OpenWeatherMap with that data:

const { OpenWeatherAPI } = require("openweather-api-node");
const express = require("express");
const bodyParser = require("body-parser");
const path = require("path");
const app = express();
const PORT = process.env.port || 3000;

app.use(bodyParser.urlencoded({ extended: true }));
app.listen(PORT, () => console.log(`Server listening on port ${PORT}.`));

app.get("/", (req, res) => {
  res.sendFile(path.join(__dirname, "/public/views/index.html"));
});

app.post("/weather/public", (req, res) => {
  let city = Number(req.body.city);
  let units = (req.body.units || "").trim().toUpperCase();
  if (!["IMPERIAL, METRIC, STANDARD"].includes(units)) {
    $("h1").innerText =
      "Please input Imperial, Metric or Standard for the units.";
    return;
  }

  let weather = new OpenWeatherAPI({
    key: MY_OPENWEATHERMAP_API_KEY,
    locationName: city,
    units: units,
  });
  weather.getCurrent().then((data) => {
    res.send(
      `<p>Current temperature in ${city} is: ${data.weather.temp.cur}</p>`
    );
  });
});

The HTML itself is very simplistic:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Weather query</title>
  </head>
  <body>
    <h1>Input a city and your units!</h1>
    <form action="/weather/public" method="post">
      <input name="city" placeholder="Your city here" type="text" />
      <input
        name="units"
        placeholder="Units of Measurement (imperial, metric, standard)"
        type="text"
      />
      <button name="submit" type="submit">Calculate!</button>
    </form>
  </body>
  <script
    crossorigin="anonymous"
    integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ="
    src="https://code.jquery.com/jquery-3.6.1.min.js"
  ></script>
  <script charset="utf-8" src="../../app.js"></script>
</html>

When running the server and inputting a few items in the form, I get:

ReferenceError: $ is not defined
    at C:UsersjasoncodeWeb-Developmentweatherapp.js:19:5
    at Layer.handle [as handle_request] (C:UsersjasoncodeWeb-Developmentweathernode_modulesexpresslibrouterlayer.js:95:5)
    at next (C:UsersjasoncodeWeb-Developmentweathernode_modulesexpresslibrouterroute.js:144:13)
    at Route.dispatch (C:UsersjasoncodeWeb-Developmentweathernode_modulesexpresslibrouterroute.js:114:3)
    at Layer.handle [as handle_request] (C:UsersjasoncodeWeb-Developmentweathernode_modulesexpresslibrouterlayer.js:95:5)
    at C:UsersjasoncodeWeb-Developmentweathernode_modulesexpresslibrouterindex.js:284:15
    at Function.process_params (C:UsersjasoncodeWeb-Developmentweathernode_modulesexpresslibrouterindex.js:346:12)
    at next (C:UsersjasoncodeWeb-Developmentweathernode_modulesexpresslibrouterindex.js:280:10)
    at C:UsersjasoncodeWeb-Developmentweathernode_modulesbody-parserlibread.js:137:5
    at AsyncResource.runInAsyncScope (node:async_hooks:204:9)

Line 19 is the only location in the .js file where jquery is used:

$("h1").innerText = "Please input Imperial, Metric or Standard for the units.";

I changed the location of the <script> tag for jquery to be inside the <head> block but this did not help. I’m wondering whether it is even possible for me to use jquery inside Express’ handlers or whether this is impossible and I should instead send an error HTML file as a response.

Add a bookmark if there is none in this position. (AppScript)

Part of my script needs to add a bookmark to every H2 paragraph in a google document, save it’s text content and the bookmark’s url to use later.

The problem is that each time the script runs it creates more and more bookmarks and I can’t manage to get the bookmark url to save.

//////////////

var doc = DocumentApp.openById('your document ID here');
var body = doc.getBody();
// Define the search parameters.
var searchType = DocumentApp.ElementType.PARAGRAPH;
var searchHeading = DocumentApp.ParagraphHeading.HEADING2;
var searchResult = null;
var headingsList = [];
var urlList = [];
 

// Search until the paragraph is found.
while (searchResult = body.findElement(searchType, searchResult)) {
    var par = searchResult.getElement().asParagraph();
    if (par.getHeading() == searchHeading) {
        headingsList.push(par.getText());
    doc.addBookmark(doc.newPosition(par, 0));
    }
}

// This is the part of the code I managed to write, it works for creating the bookmarks (albeit multiple ones on top of each other) and it successfully saves the header text to an array.

How to fetch a url of a backend route in react native? [closed]

How to fetch a url of a backend route in react native? i have hosted a backend nodejs sever on render.com and it gave me a url https://hereismyservername.onrender.com and when i go this url it gave me hello world in have a given but i do want to use this url on my react native app to fetch how can i fetch this? i have a login route that i want to fetch how can i do that? that login route is there at routes folder then auth file

i tried this https://hereismyappcode.onrender.com/login but not working