Finding a pattern in an array that is not always consistant

I have an ordered data set of decimal numbers. This data is always similar – but not always the same. The expected data is a few, 0 – 5 large numbers, followed by several (10 – 90) average numbers then follow by smaller numbers. There are cases where a large number may be mixed into the average numbers’ See the following arrays.

let expectedData = [35.267,9.267,9.332,9.186,9.220,9.141,9.107,9.114,9.098,9.181,9.220,4.012,0.132];



let expectedData = [35.267,32.267,9.267,9.332,9.186,9.220,9.141,9.107,30.267,9.114,9.098,9.181,9.220,4.012,0.132];

I am trying to analyze the data by getting the average without high numbers on front and low numbers on back. The middle high/low are fine to keep in the average. I have a partial solution below. Right now I am sort of brute forcing it but the solution isn’t perfect. On smaller datasets the first average calculation is influenced by the large number.

My question is: Is there a way to handle this type of problem, which is identifying patterns in an array of numbers?

My algorithm is:

  1. Get an average of the array
  2. Calculate an above/below average value
  3. Remove front (n) elements that are above average
  4. remove end elements that are below average
  5. Recalculate average

In JavaScript I have: (this is partial leaving out below average)

let total= expectedData.reduce((rt,cur)=> {return rt+cur;}, 0);
let avg = total/expectedData.length;
let aboveAvg = avg*0.1+avg;
let remove = -1;
 
for(let k=0;k<expectedData.length;k++) {
    if(expectedData[k] > aboveAvg) {
    remove=k;
    } else {
        if(k==0) {
            remove = -1;//no need to remove
        } 
          //break because we don't want large values from middle removed.
        break;
        }
}
if(remove >= 0 ) {
//remove front above average     
 expectedData.splice(0,remove+1);
 
}

//remove belows
//recalculate average 

When I click the link (react-router used) it takes me to the middle of the linked page instead of top (More explanation in description)

So basically when i click on the learn more button of example the SEO service , It opens the SEO page successfully however, it opens it in the middle instead of from the beginning.

Below is my app.js where I have my routes

import {BrowserRouter as Router , Routes, Route} from 'react-router-dom'

function App() {
  return (
    <>
      <Router>
        <Routes>
            <Route path="/" exact element={<HomePage/>} />
            <Route path="/whowehelp" exact element={<WhoWeHelp/>} />
            <Route path="/about" exact element={<AboutPage />} />
            <Route path= "/services" exact element= {<ServiceGeneralPage />} />
            <Route path="/caseStudy" exact element={<CaseStudyPage />} />
            <Route path="/contact" exact element={<ContactUs />} />
            <Route path="/seo" exact element={<SEO />} />
            <Route path="/facebook" exact element= {<Facebook />} />
            <Route path="/website" exact element= {<Website />} />
            <Route path="/googleads" exact element={<GoogleAds />} />
            <Route path="/content" exact element={<Content />} />
        </Routes>
      </Router>
      </>
  );
}

The code below is an example of what my SEO.js looks like

const SEO = () => {
  return (
    <>
        <SocialsHeader />
        <Navbar />

        <WhoWeHelpBanner
          title= "SEO"
          img= {seoServiceBanner}
          desc= {<p>Search engine optimization serves to help your website <br />
           rank organically through on-page and backend website <br />
            optimizations.</p>}
            
        />

        <div className={styles.gridContainer}>
            <SEOLeft 
            title= "Get on Google’s 1st Page"
            desc= "Leveraging your unique benefits and standing out among your competitors matters the most for your business ranking. We offer highly professional SEO services to achieve this goal. Our SEO specialists spend hours every month continuously optimizing your main web pages, blog posts, listings profiles, and more. SEO is a constant effort to keep up with Google's ever-changing algorithms."
            />

            <SEORight 
            img= {seoPic} 
            />

            <SEORight 
            img= {seoPic2}
            />

            <SEOLeft 
            title= "Top Rankings"
            desc= "A key part of SEO services is helping your business rank higher. There are a number of factors that go into this including keyword usage, page load times, current website traffic, web design layout, content relevancy, and much more. Our SEO experts specialize in everything it takes to help you rank higher until you're number one."
            />

            <SEOLeft 
            title= "Keyword Ranking Reporting"
            desc= "We perform extensive keyword research and find out the best ones that symbolize your business and match with what the customers are using on their daily web searches. Stay in-the-know with all the industry-specific keywords that are being tracked on your campaign."
            />

            <SEORight 
            img= {seoPic3}
            />

            <SEORight 
            img= {seoPic4}
            />

            <SEOLeft 
            title= "Imperative KPIs"
            desc= "Set your goals and objectives to gear toward snowballing the value of your company. While tracking the Key Performance Indicators (KPIs), your company will be able to make adjustments to various strategies and budgets."
            />
        </div>
    </>
  )
}

)
}`

I am kind of a beginner to this so solving this glitch on my own is pretty hard, thanks in advance !

I was expecting the page to load from the top but for some reason It loads at the bottom , could this have to do with the React Router bugging or something.

HTML Slideshow – Images not showing

My slideshow is not working (HTML, CSS, JS). This is how it looks my code right now:

HTML

<div class="slideshow-container">
<div class="mySlides fade">
<div class="numbertext">1 / 3</div>

<div class="text">Nuestra cafetería</div>
</div>

          <div class="mySlides fade">
            <div class="numbertext">2 / 3</div>
            <img src="imgMocha-Lounge.jpg" style="width:100%">
            <div class="text">Nuestra cafetería</div>
            </div>
        
          <div class="mySlides fade">
            <div class="numbertext">3 / 3</div>
            <img src="imgmochagirl.jpg" style="width:100%">
            <div class="text">Nuestra cafetería</div>    
            </div>

            <a class="prev" onclick="plusSlides(-1)">&#10094;</a>
            <a class="next" onclick="plusSlides(1)">&#10095;</a>
            </div>
            <br>

            <div style="text-align:center">
                <span class="dot"></span> 
                <span class="dot"></span> 
                <span class="dot"></span> 
            </div>`

CSS

* {box-sizing: border-box}

.mySlides {
display:none;
}

img {vertical-align: middle;}

.slideshow-container {
max-width: 1000px;
position: relative;
margin: auto;
height: 300px;
margin-top: 10px;

}

.prev, .next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
margin-top: -22px;
padding: 16px;
color: white;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
}

.next {
right: 0;
border-radius: 3px 0 0 3px;
}

.prev:hover, .next:hover {
background-color: rgba(0,0,0,0.8);
}

.text {
color: #f2f2f2;
font-size: 15px;
padding: 8px 12px;
position: absolute;
bottom: 8px;
width: 100%;
text-align: center;
}

.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}

.dot {
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}

.active, .dot:hover {
background-color: #717171;
}

.fade {
animation-name: fade;
animation-duration: 1.5s;
}

@keyframes fade {
from {opacity: .4}
to {opacity: 1}
}

@media only screen and (max-width: 300px) {
.prev, .next,.text {font-size: 11px}
}

JS
let slideIndex = 0;
showSlides();

function showSlides() {
let i;
let slides = document.getElementsByClassName("mySlides");
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}

slideIndex++;

if (slideIndex > slides.length) {slideIndex = 1}
slides[slideIndex-1].style.display = "block";
setTimeout(showSlides, 2000);

I’m trying to make a slideshow

my redux toolkit state is not updating properly

My redux toolkit dispatch is firing twice, once immediately which for some reason doesn’t properly update the state, then my entire app breaks because it cant’t find the info that us supposed to have been provided, then it fires again and updates properly. So if i refresh the page then everything will load up because then it gets the information from my persistent storage in time.

This is the portion of the code where the dispatch is called:

const handleSignUp = (e) => {
    e.preventDefault();

    createUserWithEmailAndPassword(auth, email, password)
      .then((cred) => {
        updateProfile(cred.user, { displayName: name })
          .then(() => {
            dispatch(
              login({
                name: name,
                uid: cred.user.uid,
                jobDesc: jobDesc,
                email: email,
              })
            );
          })
      })
      .catch((err) => {
        console.log(err);
      })
      .finally(() => {
        setPassword("");
      });
  };

This is the userSlice where login is called from:

import { createSlice } from "@reduxjs/toolkit";

const initialState = {
  user: null,
};

export const userSlice = createSlice({
  name: "user",
  initialState,

  reducers: {
    login: (state, action) => {
      state.user = action.payload;
    },
    logout: (state) => {
      state.user = null;
    },
  },
});

export const { login, logout } = userSlice.actions;

export default userSlice.reducer;

i have checked my redux dev tools so i know the dispatch calls twice and if first udpates partially and the completely.

this is text copied from my dev tools console that displays the state and it’s changes:

name(pin):null
uid(pin):”CK3uLpCLD3hIOa0vXEzhA0oFcwr1″
email(pin):”[email protected]”

that is the first update and this is the second:

name(pin):”james”
uid(pin):”CK3uLpCLD3hIOa0vXEzhA0oFcwr1″
jobDesc(pin):”web dev”
email(pin):”[email protected]”

I’ve almost lost my mind trying to figure this out, please help.

jQuery code should fire after on.change()

I’m having trouble with a jQuery function, I created a Fiddle for it:

–> Fiddle <–

So far the function did what it should do which is showing or hiding content based on simple checkbox values. Now what it also does is removing a pre-existing class from the hidden content so that only the visible elements will still have that class. It gets added back to the hidden elements once they are visible again.

The purpose: I want to address the newly created last child of that class in its container. Let’s say these are the elements before:

<div class="container">
    <div class="location-wrap location-show"></div>
    <div class="location-wrap location-show"></div>
    <div class="location-wrap location-show"></div>
    <div class="location-wrap location-show"></div> <!-- the original .container .location-show:last-child -->
</div>

And these are the elements after the on.change() –> some are hidden and the class .location-show is taken from them while it was added to those who show:

<div class="container">
    <div class="location-wrap" style="display: none;"></div>
    <div class="location-wrap" style="display: none;"></div>
    <div class="location-wrap location-show"></div> <!-- this should be the new .container .location-show:last-child -->
    <div class="location-wrap" style="display: none;"></div>
</div>

So my question is: How can I fire code that runs AFTER the on.change and addresses the newly created last child “.location-show” of its container “.container”? No matter what I tried, it will always go straight for the last child that was there right from the beginning.

There is also some other code I would like to run when the dynamically created content is rendered which would also require a check for the new code how it’s presented after on.change() is done. How can I achieve that?

How to pass a dictionary to ChartJS?

I’m trying to pass a dictionary from my Flask file to my ChartJS but the data doesn’t load on my chart. I think there’s a problem on passing my data. Here is the format of my dictionary. Basically, it’s a time series dataframe I converted as dict.

[{'dates': Timestamp('2021-12-31 00:00:00'), 'cases': 2},
 {'dates': Timestamp('2022-01-01 00:00:00'), 'cases': 0},
 {'dates': Timestamp('2022-01-02 00:00:00'), 'cases': 1},
 {'dates': Timestamp('2022-01-03 00:00:00'), 'cases': 1},
 {'dates': Timestamp('2022-01-04 00:00:00'), 'cases': 1},
 {'dates': Timestamp('2022-01-05 00:00:00'), 'cases': 1},
 {'dates': Timestamp('2022-01-06 00:00:00'), 'cases': 1},
 {'dates': Timestamp('2022-01-07 00:00:00'), 'cases': 1},
 {'dates': Timestamp('2022-01-08 00:00:00'), 'cases': 1},
 {'dates': Timestamp('2022-01-09 00:00:00'), 'cases': 1},
 {'dates': Timestamp('2022-01-10 00:00:00'), 'cases': 1},
 {'dates': Timestamp('2022-01-11 00:00:00'), 'cases': 1},
 {'dates': Timestamp('2022-01-12 00:00:00'), 'cases': 1},
 {'dates': Timestamp('2022-01-13 00:00:00'), 'cases': 1}] 

Here is my flask file:

@app.route("/forecast-calculation", methods=["POST"])
    def get_result():
        days_ahead = 13
        time_steps = 30
        if request.method == "POST":
            file = request.files['file']
            basepath = os.path.dirname(__file__)
            path = os.path.join(basepath, "user-uploads", file.filename)
            df = file.save(path)
            model, scaler, df = forecast.load(path)
            pred_values = forecast.forecast(df, days_ahead, model, time_steps, scaler)
            dict = forecast.final_df(df, pred_values, days_ahead, scaler)
        return render_template("forecast-calculation.html", dict = dict)

Here is my HTML file

<canvas id="forecastCalculationchart"></canvas>
          <script>
            var parsed = JSON.parse('{{dict | tojson}}');
            labels = parsed.dates.map(function(elem){
              return elem.labels;
            })
            cases = data.cases.map(function(elem){
              return elem.cases;
            })
                const forecastCalculation = document.getElementById('forecastCalculationchart');
                const forecastCalculationchart = new Chart(forecastCalculation, {
                    type: 'line',
                    data: {
                        labels: labels,
                        datasets: [{
                            data:cases,       
                            backgroundColor: '#001F23',
                            borderColor: '#001F23',
                            borderWidth: 2,
                            tension: 0.2
    
                        }]
                    },
                    options: {
                      plugins: {
                          legend: {
                              display: false
                          }
                      }
                  }
                      
                });
            </script>

HTML rectangle box with flatter border at bottom

I want to create a box in html where the bottom is round but not a circle. I know i can add border radius bottom, see https://jsfiddle.net/cxo8usyL/

#square_1 {
  width: 100px;
  height: 250px;
  background: gold;
  border-radius: 0px 0px 50px 50px;
}

But the circle at the bottom will turn round every time. Is there a trick to make the circle flatter like in the blue one below? Current implementation (see jsfiddle in yellow), my target is in blue.

enter image description here
Target: enter image description here

Using CSS Animation from static position to fixed position

I’m trying to build a photo galley so that when you press a photo, it overlays the website, and the background turns grey, and there is an animation of the photo turning big.

This is the animation:

@keyframes img {
  0% {
    position: static;
  }

  100% {
    position: fixed;
    top: 10%;
    left: 10%;
    margin: auto;
    width: 80%;
    height: 80%;
  }
}

The problem is that css don’t animate changing the position from static to fixed.
Is there a solution to this problem?

Tried calculating the location of the image. Did not work

How to run Angular project without project files?

I am neither JS nor Angular developer, but I need to build an Angular project and be able to run it. I tried to run the project on a local server using ng serve, but this command can’t be executed outside the working directory. The directory is 1GB+, and I only need to build & run the app. Are there any ways to run already built Angular project on a local server, without project files?

Find Unique Data List from array object amenities Like result

**Filter unique object from amenities list like result using JavaScript**

amenities = [
{
“name”: “Pool”
},
{
“name”: “Laundry”
},
{
“name”: “Wifi”
},
{
“name”: “BBQ Grill”
},
{
“name”: “Barth top”
},
{
“name”: “Pool”
},
{
“name”: “Laundry”
},
{
“name”: “Wifi”
},
{
“name”: “BBQ Grill”
},
{
“name”: “Barth top”
},
{
“name”: “Pool”
},
{
“name”: “Laundry”
},
{
“name”: “Wifi”
},
{
“name”: “BBQ Grill”
},
{
“name”: “Barth top”
}
]

result = [ 
{
            "name": "Pool"
        },
        {
            "name": "Laundry"
        },
        {
            "name": "Wifi"
        },
        {
            "name": "BBQ Grill"
        },
        {
            "name": "Barth top"
        }]

Pointing tabs using CSS

Is there a way, using CSS, to make it so that when clicking a tab (as shown in the diagram below), the tab “points” to an inactive tab?

I have been trying various Stack Overflow snippets which successfully place the arrow above or below the tab, but none seem to work in overlapping the inactive tab next to the active tab.

This is the basic structure of my HTML:

<ul>
  <li class="active">
    <a href="#">Tab 1</a>
  </li>
  <li>
    <a href="#">Tab 2</a>
  </li>
  <li>
    <a href="#">Tab 3</a>
  </li>
</ul>

Image of the design to create
enter image description here

how do i make a really simple search engine

to find certain components first by their full name then by their first letter I’m using react java script .right now I’m using an array if objects “`
objects:[
{
name:’bicyle’,
details:

this would be a Component about bicyle

            },
            {
                name:'table',
                details:<p>this would be a Component about tables</p>

            },
            {
                name:'cars',
                details:<p>this would be a Component about cars</p>

            },
            {
                name:'people',
                details:<p>this would be a Component about people</p>

            },
    
        ],

 to do this and the and a method that  loops through the array checking the each objects.name to see if they match the state called *caller* which is a string that the user types then if *caller* matches objects.name then you'll set the empty state called *eye* to equal objects.details
onChange(a){
    this.setState({
        caller:a
    })
    this.state.objects.map(function(x){
        
        if (x.name == this.state.caller){
            this.setState({
                eye:this.state.objects[x]
            })
        }

    })
}

How can I fix the problem with hamburger button on mobile devices?

I’m having a problem with the hamburger button on most mobile devices where the button is pushed outside the viewport. There is no margin or padding on it, and overflow-x is hidden on the body element so I’m really struggling with finding the source of the problem. Any advice is very welcomed and code is accessible on link:
https://github.com/abarisic1509/fitness-site

I tried to change several different settings through DevTools on the header and navigation elements, but nothing seemed to work. My hamburger still looks like this

Different buttons toggling same content

there are 3 buttons and when you click 3 of them showing the same content. I need to show unique content of buttons when you click on them seperately. how to make each button should show div’s unique content?

function myFunction() {
  var x = document.getElementById("myDIV");
  if (x.style.display === "none") {
    x.style.display = "block";
  } else {
    x.style.display = "none";
  }
}
span {
cursor:pointer;}
<span onclick="myFunction()"class="total">button</span>
<div id="myDIV" style="display:none;" class="expandable">
   content 1
</div>
<span onclick="myFunction()" class="total">button2</span>
<div id="myDIV" style="display:none;" class="expandable">
   content 2
</div>
<span onclick="myFunction()" class="total">button3</span>
<div id="myDIV" style="display:none;" class="expandable">
   content 3
</div>