How to do filtering on the basis of checkboxes checked with data coming from API

I want to filter the dealer on the basis of selected rating checkboxes value. When user select the one star ,want the dealers with one star only and if user selects the two star, then dealers with two star and one star. I am storing the checboxes value using useState and getting an array.How to unfiltered data if the checkbox that is selected is unchecked.

 const [dealersData, setDealersData] = useState<Dealer[]>([]);
    const [filteredData, setFilteredData] = useState<Dealer[]>(dealersData);
    const [activeFilter, setactiveFilter] = useState<number[]>([]);
    
    const onFilterChange = (e: React.ChangeEvent<HTMLInputElement>) => {
           console.log(e.target.value);
        if(e.target.checked){
        let data = activeFilter;
        activeFilter.push(Number(e.target.value));
        setactiveFilter(data);
        }else{
            let data=activeFilter.filter((value) =>(Number(e.target.value) != value));
            console.log('inactivedata',data);
            setactiveFilter(data);
            console.log(activeFilter);
        }
        let ratingResult: React.SetStateAction<Dealer[]> = [];
        activeFilter.forEach((item)=>{
            switch(item){
                case 1:
                   ratingResult= dealersData.filter((dealerData) =>{
                   return dealerData.dealer_history.some(dataItem =>(dataItem.rating >= 1 && dataItem.rating < 5));
                 });
                 break;
                 case 2:
                   ratingResult= dealersData.filter((dealerData) =>{
                   return dealerData.dealer_history.some(dataItem =>(dataItem.rating >= 2 && dataItem.rating < 5));
                 });
                 break;
                 case 3:
                    ratingResult= dealersData.filter((dealerData) =>{
                    return dealerData.dealer_history.some(dataItem =>(dataItem.rating == 3 && dataItem.rating < 5));
                  });
                  break;
                  case 4:
                    ratingResult= dealersData.filter((dealerData) =>{
                    return dealerData.dealer_history.some(dataItem =>(dataItem.rating == 4 && dataItem.rating < 5));
                  });
                  break;
                  case 5:
                    ratingResult= dealersData.filter((dealerData) =>{
                    return dealerData.dealer_history.some(dataItem =>(dataItem.rating == 5));
                  });
                  break;
                };
        });
        setFilteredData(ratingResult);
        }
    
      <div><Checkbox color="primary" value="5" onChange={(e) => onFilterChange(e)} /><Rating name="size-small" size="small" value={5} readOnly /></div>
                                            <div><Checkbox color="primary" value="4" onChange={(e) => onFilterChange(e)} /><Rating name="size-small" size="small" value={4} readOnly /></div>
                                            <div><Checkbox color="primary" value="3" onChange={(e) => onFilterChange(e)} /><Rating name="size-small" size="small" value={3} readOnly /></div>
                                            <div><Checkbox color="primary" value="2" onChange={(e) => onFilterChange(e)} /><Rating name="size-small" size="small" value={2} readOnly /></div>
                                            <div><Checkbox color="primary" value="1" onChange={(e) => onFilterChange(e)} /><Rating name="size-small" size="small" value={1} readOnly /></div>
    
    export interface Dealer{
        dealer_id:number,
        name:string,
        mobile:number,
        email:string,
        gst_no:string,
        locality:string,
        city:string,
        state:string,
        pincode:string,
        vehicle_type_id:number,
        Vehicletype:{
            vehicle_type:string
        };
        Services:[
            {
                discription:string,
                cost:number
            }
        ],
        dealer_history:[
            {
                rating:number,
                comments:string
            }
        ]
    }

expression not in aggregate or GROUP BY columns

I have a table that contains the following columns:
ProductID, ProductName, Price, CategoryID.

The goal is to print all the details (ProductID, ProductName, Price, and Category) about the most expensive product.

I executed the following query:

str = "SELECT ProductID, ProductName, MAX(Price) AS MaxPrice, CategoryID FROM Products;";   

However, the exception mentioned in the title appears, and I do not find a reason for the exception appearance. I searched for explanations on the following links:

I have also read and practiced in SQL Lesson 10: Queries with aggregates (Pt. 1)
According to my checking in SQLBolt, the way I wrote the query is acceptable.

After reading and practicing, I still do not understand why I need to use the GROUP BY here. It’s not that I need to present the maximum price of each group…

Thank you very much beforehand!

query-string in react router v6

I show two query strings in my URL like this **localhost3000/?filter=all&search=something**
but the problem is when there isn’t anything for search my URL still shows **localhost3000/?filter=all&search=**
while I want to show search if it uses and when there is no search it shows **localhost3000/?filter=all**
this is my code:

  replaceUrl = () => {
    const x = {
      filter: this.state.filter,
      search: this.state.searchterm,
    };
    const y = queryString.stringify(x);
    this.props.navigate(`?${y}`);
  };

replaceUrl calls when filter changes or something search

Add an object:value to a constructor’s property

I have a constructor like this

class Class1 {
constructor(name, age, sports,){

this.name = name;
this.age = age;
this.sports = sports
}


}

Where I recieve arguments like this:

const robert = new Class1('robert',26,{rugby: good, tenis: bad})

that I want to add to the properties and I cant figure it out how to do it

This is how it should look:

this.name = robert;
this.age = 26;
this.sports = {rugby: good, tenis: bad}

Help will be apreciated

AWS IVS Playback key across multiple private channels?

Hello I see there’s a limit of 3 playback key pairs. Can I use a keypair across multiple private channels? My use case is a ugc streaming app where all channels are paid for and require authorization to view.

Workflow for a private channel is as follows:

1)When a viewer tries to load the webpage for a private stream, the browser requests an access token. (The customer provides the browser code to do this.)

2)The customer’s backend app receives the access-token request and determines whether that viewer should be authorized to view the stream. If yes, the backend generates a JWT, uses the customer’s private key to sign it, and returns the signed JWT in a playback request to the browser.

3)The browser loads the stream, using a request to the Amazon IVS player (or other player) SDK. The request contains the stream playback URL and the signed JWT.

4)Amazon IVS uses the customer’s public key to verify that the JWT was signed using the correct private key.

5)If the JWT is verified, Amazon IVS plays the private stream for the viewer.

get unique objects from 2 array of objects

I have 2 array of objects:

marketingCarriers: 
[
   {
     code: "AM"
     logo: "logo1.png"
     name: "AEROMEXICO"
   }
]

operatingCarriers: 
[
  {
    code: "DL"
    logo: "logo12.png"
    name: "DELTA"
  },
  {
    code: "AM"
    logo: "logo1.png"
    name: "AEROMEXICO"
  }
]

I want to make an array by comparing these two array of objects where I will put the unique objects from these 2 arrays.
So the output will be:

newArray: 
    [
      {
        code: "DL"
        logo: "https://meta-staging.welltravel.com/media/W1siZiIsIjIwMTcvMTIvMDgvMDkvMzUvMjRhY2FjZjktZjc5Zi00YWUyLWI0Y2MtZDgxMDViMjkzZWM2Il1d?sha=d121026cc0675306"
        name: "DELTA"
      }
    ]

What should be the process?

I am trying to disable the timer function running in the background of a page that i do not own

Previously I simply input the command vTimereq=0 into the console and that seem to do the trick. However now when I try it nothing happens and the timer continues to run. I have tried a few things such as document.getElementById(‘time’).value = “0”; but that command also seems to be invalid. Any help would be greatly appreciated. This is the function that appears when I try to edit 00:04:26

How make input radio value as number? [duplicate]

I am trying do arithmetic operation using radio button (just an experiment)

browser returns value NaN

let num1 = parseInt(document.querySelectorAll('#number1:checked'));
let num2 = parseInt(document.querySelectorAll('#number2:checked'));

function addTambah() {
  result = num1 + num2;
  alert(result);
}
<p>number : </p>
<input type="radio" name="number1" id="number11" value="1">
<label for="radio">1</label>
<input type="radio" name="number1" id="number12" value="2">
<label for="radio">2</label>
<p> number 2 : </p>
<input type="radio" name="number2" id="number21" value="1">
<label for="radio">1</label>
<input type="radio" name="number2" id="number22" value="2">
<label for="radio">2</label>
<br>
<button type="button" onclick="addTambah()">Add</button>

React error “Objects are not valid as a React child (found: [object Promise])”

I’m pretty new to React. I’m trying to create a private route handler with the new release of react-router-dom v6, so I need to verify whether the user is authenticated or not in order to know if return the protected route or redirect the user to the login route.

import { Navigate } from 'react-router-dom';
import { useSelector } from 'react-redux';
import { isLogged } from '../helpers/isLogged';

export const PrivateRoute = async ({children}) => {

  // Check if the user is authenticated 
  const userData = useSelector( store => store.user.object);
  const logged = await isLogged(userData);

  return logged 
  ? children
  : <Navigate to="/login" />;
}

The thing is i’m getting some errors due to this, but mainly the object promise one.

What’s going on? Thanks in advance!

Expected a JSON object, array, or literal

I’ve copied code from a course I’m taking and it’s throwing an error. The message reads “Expected a JSON object, array, or literal” and I’m not entirely sure what I’ve done wrong since I’m new to using API’s (fetch). Here is the screenshot from VSCode. https://www.screencast.com/t/D5oreexoCKq.

In addition to that, this is the error that I’m getting in Chrome. https://www.screencast.com/t/Je4crxQQ4sz6

file —–> data.json

const json = {
    "books": [
        {
            "title": "Learn to Code",
            "author": "John Smith",
            "isbn": "324-23243"
        }, {
            "title": "The Adventures JSON",
            "author": "Jason Jones",
            "isbn": "3324-2-444"
        }, {
            "title": "New Objects",
            "author": "Jane Doe",
            "isbn": "2343-234-2433"
        }
    ]
}

file —–> app.js

JSON.books.forEach(function(val){
  console.log(val);
})

How to retrieve the respective value from the checkbox to display in the div based on search text?

I have a searchbar, 2 divs that will display the id and brand name, and 2 checkboxes.

I want to retrieve brand data according to search, if I search for “Nike” then the brand-id and brand-name divs will display the brand name and id based on the checkbox below. And the checkbox below it is ticked. I’ve coded like below, but when I debug to get the brand name it merges “nikebrand”, so when I do a conditioning it doesn’t work

$('.search-brand').on('keyup keypress',function(){
  const brandFilterEl = $(".filter-item .filter-label")
  
  brandFilterEl.each(function(){
    const brandValues = brandFilterEl.text().toLocaleLowerCase()
    console.log(brandValues)
    
    if($('.search-brand').val() === brandValues){
      const valFilterBrand = brandFilterEl.siblings().attr('value')
      console.log(valFilterBrand)
      $('.brand-id').text(valFilterBrand)
      $('.brand-name').text(brandValues)
    }
  })
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" class="search-brand" style="margin-bottom:20px;">

<div class="brand-id"></div>
<div class="brand-name"></div>

<li class="filter-item" style="padding-left: 20px; font-size: 12px; padding-bottom: 0; border: none;">
   <input type="checkbox" name="brandIds" value="3" style="margin-right: 5px"> <span class="filter-label">Nike</span>
</li>
<li class="filter-item" style="padding-left: 20px; font-size: 12px; padding-bottom: 0; border: none;">
  <input type="checkbox" name="brandIds" value="2" style="margin-right: 5px"> <span class="filter-label">Adidas</span>
</li>

Toggling JS button back and forth

my toggle button in javascript seems to work fine in turning on lightmode from default darkmode by running a function that changes the CSS. However, when I flip the button again, it does not change. This is somewhat expected since there’s no reason it would change. How would I go about switching it back?

Button HTML:

<label for="ID_HERE" class="toggle-switchy" >
    <input checked type="checkbox" id="ID_HERE">
        <span class="toggle" onclick="lightmode();"></span>
      <span class="switch"></span>
    </span>
</label>

JS for button:


function lightmode() {
  const bodyChanges = document.querySelectorAll('.margin_body');
  for (let i = 0; i < bodyChanges.length; i++) {
    bodyChanges[i].style.background = 'white';
  }
  /*const bodyChanges = document.querySelectorAll('.margin_body');
  for (let i = 0; i < bodyChanges.length; i++) {
    bodyChanges[i].style.backgroundImage = '';
  } */

  const paraChanges = document.querySelectorAll('.paragraph');
  for (let i = 0; i < paraChanges.length; i++) {
    paraChanges[i].style.color = 'black';
  }
  const topTitleChanges = document.querySelectorAll('.toptitle');
  for (let i = 0; i < topTitleChanges.length; i++) {
    topTitleChanges[i].style.color = 'black';
  }
  const alphabetSChanges = document.querySelectorAll('.AlphabetS');
  for (let i = 0; i < alphabetSChanges.length; i++) {
    alphabetSChanges[i].style.color = 'black';
  }
  const arowanaContainerChanges = document.querySelectorAll('.arowanacontainer');
  for (let i = 0; i < arowanaContainerChanges.length; i++) {
    arowanaContainerChanges[i].style.background = 'white';
  }
  const fishContainerChanges = document.querySelectorAll('.fishcontainer');
  for (let i = 0; i < fishContainerChanges.length; i++) {
    fishContainerChanges[i].style.background = 'white';
  }
  const articleContainerChanges = document.querySelectorAll('.articlescontainer');
  for (let i = 0; i < articleContainerChanges.length; i++) {
    articleContainerChanges[i].style.background = 'white';
  }
  const sideTextChanges = document.querySelectorAll('.sidetext');
  for (let i = 0; i < sideTextChanges.length; i++) {
    sideTextChanges[i].style.color = 'black';
  }
  const topMenuChanges = document.querySelectorAll('.topmenu');
  for (let i = 0; i < topMenuChanges.length; i++) {
    topMenuChanges[i].style.background = '#fff2f2';
  }
  const h3Changes = document.querySelectorAll('h3');
  for (let i = 0; i < h3Changes.length; i++) {
    h3Changes[i].style.background = '#fff2f2';
  }
  const articlePageChanges = document.querySelectorAll('.articlepage');
  for (let i = 0; i < articlePageChanges.length; i++) {
    articlePageChanges[i].style.color = 'black';
  }
  const articleTeaserChanges = document.querySelectorAll('.articleteaser');
  for (let i = 0; i < articleTeaserChanges.length; i++) {
    articleTeaserChanges[i].style.color = 'black';
  }
  /*const buttonTextChanges = document.querySelectorAll('.button_text');
  for (let i = 0; i < buttonTextChanges.length; i++) {
    buttonTextChanges[i].style.color = '#0C0C0C';*/
  const box2Changes = document.querySelectorAll('.box2');
  for (let i = 0; i < box2Changes.length; i++) {
    box2Changes[i].style.color = 'rgb(245, 245, 245)';
  }
  const box3Changes = document.querySelectorAll('.box3');
  for (let i = 0; i < box3Changes.length; i++) {
    box3Changes[i].style.color = 'rgb(245, 245, 245)';
  }
  const projectPhoto1Changes = document.querySelectorAll('.projectphoto1');
  for (let i = 0; i < projectPhoto1Changes.length; i++) {
    projectPhoto1Changes[i].style.backgroundImage = 'linear-gradient(to bottom, #Fdfcfa 50%, lightgrey 50%)';
  }
  const section1Changes = document.querySelectorAll('.section1');
  for (let i = 0; i < section1Changes.length; i++) {
    section1Changes[i].style.backgroundColor = '#fff2f2';
  }
  const section1textChanges = document.querySelectorAll('.section1text');
  for (let i = 0; i < section1textChanges.length; i++) {
    section1textChanges[i].style.color = 'black';
  }
  const section1smalltextChanges = document.querySelectorAll('.section1smalltext');
  for (let i = 0; i < section1smalltextChanges.length; i++) {
    section1smalltextChanges[i].style.color = 'black';
  }
  const button_textChanges = document.querySelectorAll('.button_text');
  for (let i = 0; i < button_textChanges.length; i++) {
    button_textChanges[i].style.color = 'black';
  }
  const polygonfrontChanges = document.querySelectorAll('.polygonfront');
  for (let i = 0; i < polygonfrontChanges.length; i++) {
    polygonfrontChanges[i].style.fill = '#fff2f2';
  }
  const bgChanges = document.querySelectorAll('.bg');
  for (let i = 0; i < bgChanges.length; i++) {
    bgChanges[i].style.backgroundImage = 'url(".jpg")';
  }
  const bg2Changes = document.querySelectorAll('.bg2');
  for (let i = 0; i < bg2Changes.length; i++) {
    bg2Changes[i].style.backgroundImage = 'url(".jpg")';
  }
  const bg3Changes = document.querySelectorAll('.bg3');
  for (let i = 0; i < bg3Changes.length; i++) {
    bg3Changes[i].style.backgroundImage = 'url(".jpg")';
  }
  
}

Please help me to solve this question in C# [closed]

TechWorld is a technology training center, providing training to their clients on various technologies.They need to automate the process of allocating instructors for different courses. An instructor is identified by his/her name and may be skilled in multiple technologies. Assume that the skills of an instructor are stored in an array.

Class Diagram:
enter image description here

  • Instructor Class

Note:

The methods implementing the below requirements should return True for valid cases and False for invalid cases.

Assume “experience” is a positive integer.

Case sensitive string comparisons should be done wherever required.

  • Parameterized Constructor – Instructor(string, float, int, string[])

It should initialize the member variables ‘instructorName’, ‘avgFeedback’, ‘experience’ and ‘instructorSkill’ with appropriate values.

  • ValidateEligibility() method

The method should check the eligibility criteria as given below:

An instructor with more than 3 years of experience should have an average feedback greater than or equal to 4.5.

An instructor with less than or equal to 3 years of experience should have an average feedback greater than or equal to 4.

  • CheckSkill(string technology) method

This method should accept a technology name as input parameter and check whether the instructor possesses that skill.

For checking validity of instructor call ValidateEligibilty() method

I am not able to compare the values of the state variables even though I am able to fetch their values in the rock-paper-scissor game

Please help me out with this:

I was making a react app for a rock-paper-scissors game where I was trying to evaluate whether the move made the user or bot the winner by comparing the values through a function written in check.js . But it seems the answer is always undefined. For understanding this issue, I tried to just compare an instance as you will be able to see below in App.js ‘s useEffect Hook. It only compares correctly when the state-variables are empty ( initial state ). The reference to the code section is given below where inside “useEffect” hook, the console.log should have printed draw but it returns nothing. The link to the sandbox project is given at the end as well.

    import { useEffect, useState } from 'react';
import './App.css';
import './App.css'
import Botchoice from './Components/Botchoice';
import Decision from './Components/Decision';
import Navbar from './Components/Navbar';
import Results from './Components/Results';
import Userchoice from './Components/Userchoice';
import game from './check'

function App() {

  let [userMove,setUserMove] = useState("");
  let [botMove,setBotMove] = useState("");
  let [loadRes, setLoadRes] = useState("");
  let [gameState,setGameState] = useState("");


  useEffect(() => {
          setTimeout(() => {
            console.log(userMove, botMove);
            
            if (userMove === "scizzor" && botMove === "scizzor") {
              console.log("draw");
            }

          }, 1000);
      },[userMove,botMove])


  const getUserMove = (move) => {

    setUserMove(()=> userMove = move);
    console.log("App comp: usermove --> " + userMove);

  }

  const getBotMove = (move) => {

    setBotMove(()=> botMove = move);
    console.log("App comp: botmove --> " + botMove);

  }

  const getLoadRes = (value) => {

      setLoadRes(()=> loadRes = value )
      console.log("updated state: " + loadRes);

  }

 
  
  return (
    <div className="App">
      
      <Navbar/>
      <Userchoice getUserMove={getUserMove} />
      <Botchoice getBotMove={getBotMove} />
      <Decision getLoadRes={getLoadRes} />

      {loadRes === "show" 
        ? <Results userMove={userMove} botMove={botMove} />
        : null
      }



    </div>
  );
}

export default App;

I have also attached the screenshot of the console inorder to show the values of userMove and botMove and yet how the if condition inside useEffect is unable to compare these values.

Screenshot of the console

Please help me out with this as I’m stuck as to what is causing this issue. Thanks

Here is the link to my sandbox of the rock-paper-scissors game

how to make the dda line using only the :* and # icons

how to make the dda line using only the :* and # icons. please answer please.
so I want to make my program on console.log view like this:
O……….
.O………
..O……..
…O…….
….O……
…..O…..
……O….
…….O…
……..O..
………O.
……….O

and this is like a diagonal but according to the name of my function dda where point a = 2.1 and point b = 8.5

you can immediately see the implementation of this in java form but only want it in javascript form

https://ideone.com/Jx3DaO

function dda(x1, y1, x2, y2) {
    const
        dx = x2 - x1,
        dy = y2 - y1,
        step = Math.abs(dx) > Math.abs(dy)
            ? Math.abs(dx)
            : Math.abs(dy),
        x_inc = dx / step,
        y_inc = dy / step,
        result = [];

    for (let k = 0, x = x1, y = y1; k < step; k++) {
        result.push([ Math.round(x), Math.round(y)]);
        x += x_inc;
        y += y_inc;
    }

    return result;
}

console.log(dda(2, 1, 8, 5));