Inability to successfully upload batch data within specified criteria using a keyword and conditional statement

My goal is to batch the data, using "Repair" as a separator for the data.
Splitting criteria = Repair
Copper limit = 2.5

[
  {"engineSN":"20","timeRun":"30","Cu":"2"},
  {"engineSN":"20","timeRun":"40","Cu":"2.01"},
  {"engineSN":"20","timeRun":"59","Cu":"2.5", "Decision":"Repair"},
  {"engineSN":"20","timeRun":"74","Cu":"5.4"},
  {"engineSN":"20","timeRun":"90","Cu":"3.4", "Decision":"Repair"},
  {"engineSN":"20","timeRun":"130","Cu":"5.6"},
  {"engineSN":"20","timeRun":"1800","Cu":"10.3"},
]

I attempted to iterate until the first occurrence of repair using a for loop but encountered issues.

Code:

let json = require("json.json");
let indexOfRepair = [];
let indexTemp = 0;
for(let i = 0; i < json.length; i++){
     if(json[i].Decision == 'repair'){
         indexOfRepair.push(i);
       }
}

let overLimit = [];
let underLimit =[];
let isUnderLimit = true;

for(let i = indexTemp; i < json.length; i++){
    indexTemp ++;
    if(json[i].Cu > 2.5){
        isUnderLimit = false;
        break;
        } else {
           underLim.push(json[i]);
           }
}

I'm struggling to understand why I can't separate the data as intended.

Answer â„–1

The reason for this is the use of the "break" keyword.

It stops the "for loop" from continuing any further. Instead, try using "continue" to move on to the next iteration without stopping the "for loop".

let data = require("data.json");
let indexesOfFixes = [];
let tempIndex = 0;
for (let j = 0; j < data.length; j++) {
    if (data[j].Action == 'fix') {
        indexesOfFixes.push(j);
    }
}

let overLimitValues = [];
let underLimitValues = [];
let isOverLimit = true;

for (let k = tempIndex; k < data.length; k++) {
    tempIndex++;
    if (data[k].Value > 2.5) {
        isOverLimit = false;
        continue; // changed from break
    } else {
        underLimitValues.push(data[k]);
    }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for transferring properties from one React component to another React component

I need to figure out how to activate a button in a modal when text is entered into an input field. The form is part of a different class and is utilized within a parent class. How can I pass an onChange method to my form component? Check out the code for ...

The custom attribute in jQuery does not seem to be functioning properly when used with the

I am currently working with a select type that includes custom attributes in the option tags. While I am able to retrieve the value, I am experiencing difficulty accessing the value of the custom attribute. Check out this Jsfiddle for reference: JSFIDDLE ...

The ng-repeat function is currently disabled and not displaying any data from the JSON object

I am currently facing an issue where the ng-repeat Directive in my code is getting commented out and not displaying the results of the JSON object. I have verified that the object is being properly passed to "this.paises2" using the toSource() method, and ...

Use ASP.NET MVC to pass data from an action to an AJAX call and utilize it in the success function

I have a custom ResultOfOperation class that I use to retrieve details about an activity: public class ResultOfOperation { public string Message1 { get; set; } public string Message2 { get; set; } public string Message3 { get; ...

Stop Code Execution || Lock Screen

Is there a way to address the "challenge" I'm facing? I'm an avid gamer who enjoys customizing my game using JavaScript/jQuery with Greasemonkey/Firefox. There are numerous scripts that alter the DOM and input values. In my custom script, I hav ...

Effortlessly move events to a different calendar using the tab menu feature in FullCalendar

My issue involves having multiple calendars within a tab container that can be switched using a navigation menu. I want to be able to drag events between these calendars using the navigation menu, but I encounter an error where if I switch tabs while dragg ...

Issues with AngularJS Directives not functioning properly when elements are added dynamically through an AJAX request

I am facing a scenario where I have a page featuring a modal window that is created using the AngularUI Bootstrap modal directive. The DOM structure for this modal is being dynamically loaded from the server, and it is triggered to open when a specific but ...

Scroll-triggered Autoplay for YouTube Videos using JQuery

Issue: I'm trying to implement a feature where a YouTube video starts playing automatically when the user scrolls to it, and stops when the user scrolls past it. Challenges Faced: I am new to JavaScript web development. Solution Attempted: I referre ...

Transforming JSON data into an organized dataframe structure

I have some data stored in variables: results = requests.request("POST", url, headers=headers, data=payload).json() results {‘ABC: {’26/03/2021': {‘A’: ‘1234’, ‘B’: ‘5678’}, '29/03/2021': {‘A’: ‘5555â ...

The proper method for redirecting the view after a successful AJAX request in a MVC application

Explanation of the Issue: I have added a search function to the header section of my MVC website. It includes an input text box and a 'Search' button. The Problem at Hand: Currently, I have incorporated an AJAX function in the shared master la ...

utilizing the JavaScript SDK to send alerts to a user's friends on Facebook

I am attempting to send a notification to a user's friend using the JS SDK on a Facebook canvas app, but I'm encountering this error in the console: POST https://graph.facebook.com/16542203957691/notifications? 400 (OK) jquery.min.js:140 c.exten ...

Maximizing JavaScript efficiency: Returning a value within an if statement in an AJAX call

In my function, I have a condition that checks the idType. If it is 1, an ajax call is made to a php file to retrieve the name associated with the specific idName and return it. Otherwise, another example value is returned. function obtainName(idName, idTy ...

When the horizontal scroll is turned off, it also disables the functionality of my mobile-friendly

I came across a helpful post on StackOverflow that suggested using the following code to disable horizontal scrolling: html, body { overflow-x: hidden; } This solution did resolve my issue of horizontal scrolling, but unfortunately it caused problems ...

Changing tabs will redirect the url

Having an issue with ASP AjaxControlToolkit tabs. I want the URL to change based on the tab selected by the user. Check out the code snippet below: <asp:TabContainer ID="TabContainer1" runat="server" Width="100%" Height="100%"> <asp:TabPanel ...

Executing Cascading Style Sheets (CSS) within JQuery/Javascript

I've been encountering a problem with my website. I have implemented grayscale filters on four different images using CSS by creating an .svg file. Now, I'm looking to disable the grayscale filter and show the original colors whenever a user clic ...

What is the best way to create a variable in a React component that requires asynchronously loaded data in order to be functional?

While I have a good understanding of passing data from one component to another using this.props, I am encountering difficulty in asynchronously fetching and storing values, such as from a database, that need to be accessed throughout the component. The ch ...

Determining the Clicked Button in ReactJS

I need help with a simple coding requirement that involves detecting which button is clicked. Below is the code snippet: import React, { useState } from 'react' const App = () => { const data = [ ['Hotel 1A', ['A']], ...

Guide on using Encodable or Decodable as a parameter in Swift 4

Currently, I am in the process of learning JSONParsing. After going through various tutorials, I have implemented the following code: guard let url = URL(string: "http://localhost/test-api/public/api/register") else { return } var request = URLR ...

Avoiding the sudden appearance of unstyled content in Single-File Components

I am looking to update my HTML navigation <div id="header-wrapper"> <div id="header-logo-title"> <nav> <ul id='mainNav'> <li>Home</li> </ul> </nav> ...

AngularJS Error: $interpolate:interr - Encounter with Interpolation Error

Having some trouble embedding a YouTube video into my website using AngularJS. Keep receiving this pesky error: Error: $interpolate:interr Interpolation Error Any idea why this error is popping up and how I can resolve it? Just trying to add the video... ...