Reactjs load different components when onclick()

I have two kinds of components for two languages one is EN other is FA, so I decide to run them just when HTML tag, attribute lang is equal to EN or FA,i put app.js like this:

  if(document.documentElement.lang ==='fa'){
    return (
     <div>
      <Header></Header>
      <Conference></Conference>
      <Achievements></Achievements>
      <Howtoapply></Howtoapply>
      <News></News>
      <Events></Events>
      <Calendar></Calendar>
      <Overview></Overview>
      <Footer></Footer>
     </div>
  );
  }
  else{
    return (
    <div>
      <Headeren></Headeren>
      <Howtoapplyen></Howtoapplyen>
      <Foreignstudents></Foreignstudents>
      <Conferenceen></Conferenceen>
      <Achievementsen></Achievementsen>
      <Newsen></Newsen>
      <Eventsen></Eventsen>
      <Calendaren></Calendaren>
      <Overviewen></Overviewen>
      <Footeren></Footeren>
    </div>
  );
  }

} 

it’s ok, I put onclick for HTML tag attribute lang in header.js, but it’s not working i think react just load the app.js with default index.html, HTML attribute, and when header.js change it,app.js if is not work. Header.js code is:

 function changelang(){
   document.documentElement.lang='en';
 }
 return (
   <header>
   <div className='topbar'>
     <nav className="navbar navbar-expand-lg">
       <div className="container-fluid">
         <label className="topbar-lable" htmlFor=''>دسترسی سریع:</label>
         <ul className="navbar-nav me-auto mb-lg-0">
           <li className="nav-item">
             <button onclick={changelang}>EN</button>
           </li>
         </ul>
       </div>
     </nav>
   </div> ```

How to validate data before calling onSubmit in React Hook Form?

I would simply like to validate the data on onChange. Here I have tried using rules prop from Controller but It validate data onSubmit. How can I call my position method every time there’s a change in this combobox field?

<Controller
  control={control}
  name={`${id}_${item.item_id}`}
  rules={{
    validate: {
      positive: (data) => {
        console.log(data);
        return false;
      },
    },
  }}
  render={({ field }) => {
    return (
      <EuiComboBox
        options={itemsOptions}
        placeholder="Select Item"
        isClearable={true}
        singleSelection={true}
        selectedOptions={field.value}
        onChange={field.onChange}
      />
    );
  }}
/>;

leaflet.js – how to draw leaflet arc using – start point, end point, radius and turn direction?

Question

  • Using leaflet.js I am trying to draw arc with given radius and turn direction between B and D.

JS fiddle

https://jsfiddle.net/uyLc21fm/68/

example

Inputs:

  • start LAT LON [point B]
  • end LAT LON [point D]
  • radius [in nautical miles]
  • turn direction [left or right]

Required Output:

  • yellow arc

What I have tried so far:

Leaflet.Circle

  • makes full circle not just arc par I need between B and D.

Semicircle module

  • https://github.com/jieter/Leaflet-semicircle
    problem is, this draws rather “pizza” shapes, not just arcs + requires to compute bearing start/end and center of circle. {I had both computed, but not I was hoping for.} + imprecision causes disconnected between A-B straight and B-C arc

Curve module

  • Problem: hard to set fixed radius with this one.
//var curvedPath = L.curve(
    //    [
    //        'M', latlng1,
    //        'Q', midpointLatLng,
    //        latlng2
    //    ], pathOptions).addTo(map);

constantly curved line

Below I have also tried, but they shall not be necessary for drawing/final solution – thus I consider them irrelevant.

  • I can compute center of arc.
  • I can compute start/end bearing of turn relative to arc center.

How to implement ctype.h functionality in JavaScript?

What is the general approach for translating glibc ctype.h into JavaScript? I think I could do it, but I am not finding the tables and bitshifting that implements these in the C source code. What is the most optimal techniques here?

isalnum(c)
isalpha(c)
iscntrl(c)
isdigit(c)
islower(c)
isgraph(c)
isprint(c)
ispunct(c)
isspace(c)
isupper(c)
isxdigit(c)
isblank(c)

It appears they are using all sorts of techniques to generate these functions depending on architecture perhaps. But what is the gist of what needs to be done to translate this manually to JavaScript? It appears they are using tables of some sort, but I can’t seem to also find those in the source either.

Looking at the openbsd ctype.h source gets me a little closer, but still missing the tables, and not sure if that’s the most optimized approach to use for JavaScript. For example:

__only_inline int isdigit(int _c)
{
  return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _N));
}

I don’t see where they get the & _N from, and what the (_ctype_ + 1)[index] means or comes from.

Rotate cube and pause animation-play-state

I made a HTML cube and animated its rotation after clicking on it. The cube rotates 90 degrees each time you click on it. I have an animation that makes 360 degrees.It pauses after 1/4 of animation total duration and runs again after click. That way we can see each of side faces in turn – 1,2,3,4.

But after about 10 clicks it is clear that angle is more than 90 but and view is not isometric anymore.

How to make this cube turn exactly 90 degrees and look right?

Probably it is not good to rely on duration. It could be easier if browser could watch angle and pause animation-play-state on 90, 180, 270, 360 degrees

      var spinner = document.getElementById('spinner');
      // get animation duration in ms
      var animationDuration = parseFloat(window.getComputedStyle(spinner)['animation-duration'])*1000;

      spinner.addEventListener('click', function () {
        // run animation
        spinner.style['animation-play-state'] = 'running';
        // pause animation after animationDuration / 4
        setTimeout(function () {
          spinner.style['animation-play-state'] = 'paused';
        }, animationDuration / 4);
      });
          body {
        -webkit-font-smoothing: antialiased;
        margin: 0;
      }

      * {
        box-sizing: border-box;
      }

      .container {
        background-color: #282c34;
        min-height: 100vh;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        font-size: 100px;
        color: black;
      }
      .scene {
        position: relative;
        width: 120px;
        height: 120px;
        transform-style: preserve-3d;
        transform: rotatex(-33.5deg) rotatey(45deg);
      }

      .face {
        position: absolute;
        width: 100%;
        height: 100%;
        text-align: center;
        font-size: 100px;
        background: rgba(141, 148, 249, 0.5);
        line-height: 100px;
        border: 2px solid white;
      }
      .face-front {
        transform: rotateY(360deg) translateZ(60px);
      }
      .face-right {
        transform: rotateY(90deg) translatez(60px);
      }
      .face-back {
        transform: rotateY(180deg) translatez(60px);
      }
      .face-left {
        transform: rotateY(270deg) translateZ(60px);
      }
      .face-top {
        transform: rotatex(90deg) translatez(60px);
      }
      .face-bottom {
        transform: rotatex(-90deg) translatez(60px);
      }

      #spinner {
        position: absolute;
        display: inline-block;
        width: 120px;
        height: 120px;
        left: 0;
        top: 0;
        transform-style: preserve-3d;
        animation-name: spinner;
        animation-timing-function: linear;
        animation-iteration-count: infinite;
        animation-duration: 4s;
        animation-play-state: paused;
        transform-style: preserve-3d;
      }

      @keyframes spinner {
        from {
          transform: rotateY(0deg);
        }
        to {
          transform: rotateY(-360deg);
        }
      }
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div class="container">
      <div class="scene">
        <div id="spinner">
          <div class="face face-left">1</div>
          <div class="face face-front">2</div>
          <div class="face face-right">3</div>
          <div class="face face-back">4</div>
          <div class="face face-top">5</div>
          <div class="face face-bottom">6</div>
        </div>
      </div>
    </div>
  </body>
</html>

TouchableOpacity issues caused by setState re-rendering the component

I am working on creating a custom player controls component for the react-native-video package. I use react-native-video’s onProgress event prop to store the video progress data.

This is not the exact code I am using in my project. I created a function to handle this, but it works the same as shown here:

<Video
  onProgress={ ({ currentTime }) => this.setState({ currentTime }) }
/>

Since onProgress is called every 250ms, whenever I click on a Touchable component, there is a chance my press will be cut by the component being re-rendered after the new state is set. This makes my Touchable component frequently unresponsive, and I have to end up pressing it multiple times to get the perfect timing to make it work.

I was curious if there was a way to overcome this issue. I thought about splitting everything in the component into their own small files and connect them all in one parent file, but the issue persisted. Any help would be appreciated!

Increase the size of words three.js

0

How can I solve the following issue?

I would like to increase the size of words that you are looking as a background on this page https://lovespeechgalaxy.xyz/love-galaxy/insert/navigate.php

How can achieve this and which parameter on my code should I change? How want to make them more readable (images are png).

My code

            import * as THREE from '../../build/three.module.js';

            import Stats from '../../jsm/libs/stats.module.js';

            import { GUI } from '../../jsm/libs/dat.gui.module.js';

            let camera, scene, renderer, stats, material, material2, material3, material4, material5, material6, material7;
            let mouseX = 0, mouseY = 0;

            let windowHalfX = window.innerWidth / 2;
            let windowHalfY = window.innerHeight / 2;

            init();
            animate();

            function init() {

                camera = new THREE.PerspectiveCamera( 55, window.innerWidth / window.innerHeight, 2, 2000 );
                camera.position.z = 1000;

                scene = new THREE.Scene();
                scene.fog = new THREE.FogExp2( 0x0000020, 0.001 );
                
                

                const geometry = new THREE.BufferGeometry();
                const geometry2 = new THREE.BufferGeometry();
                const geometry3 = new THREE.BufferGeometry();
                const geometry4 = new THREE.BufferGeometry();
                const geometry5 = new THREE.BufferGeometry();
                const geometry6 = new THREE.BufferGeometry();
                const geometry7 = new THREE.BufferGeometry();

                const vertices = [];
                const vertices2 = [];
                const vertices3 = [];
                const vertices4 = [];
                const vertices5 = [];
                const vertices6 = [];
                const vertices7 = [];

    const sprite = new THREE.TextureLoader().load( '../../words/hate-words/fuckyou.png' );
                const sprite2 = new THREE.TextureLoader().load( '../../words/hate-words/bastard.png' );
                const sprite3 = new THREE.TextureLoader().load( '../../words/hate-words/idiot.png' );
                const sprite4 = new THREE.TextureLoader().load( '../../words/hate-words/bitch.png' );
                const sprite5 = new THREE.TextureLoader().load( '../../words/hate-words/nigger.png' );
                const sprite6 = new THREE.TextureLoader().load( '../../words/hate-words/faggot.png' );
                const sprite7= new THREE.TextureLoader().load( '../../words/hate-words/handicapped.png' );
                

                for ( let i = 0; i < 10000; i ++ ) {

                    const x = 4000 * Math.random() - 1000;
                    const y = 2000 * Math.random() - 1000;
                    const z = 2000 * Math.random() - 1000;

                    vertices.push( x, y, z );

                }
                
                for ( let i = 0; i < 10000; i ++ ) {

                    const x = 4000 * Math.random() - 1000;
                    const y = 2000 * Math.random() - 1000;
                    const z = 2000 * Math.random() - 1000;

                    vertices2.push( x, y, z );

                }
                
                for ( let i = 0; i < 10000; i ++ ) {

                    const x = 4000 * Math.random() - 1000;
                    const y = 2000 * Math.random() - 1000;
                    const z = 2000 * Math.random() - 1000;

                    vertices3.push( x, y, z );

                }
                
                                for ( let i = 0; i < 10000; i ++ ) {

                    const x = 4000 * Math.random() - 1000;
                    const y = 2000 * Math.random() - 1000;
                    const z = 2000 * Math.random() - 1000;

                    vertices4.push( x, y, z );

                }
                
                for ( let i = 0; i < 10000; i ++ ) {

                    const x = 4000 * Math.random() - 1000;
                    const y = 2000 * Math.random() - 1000;
                    const z = 2000 * Math.random() - 1000;

                    vertices5.push( x, y, z );

                }
                
                for ( let i = 0; i < 10000; i ++ ) {

                    const x = 4000 * Math.random() - 1000;
                    const y = 2000 * Math.random() - 1000;
                    const z = 2000 * Math.random() - 1000;

                    vertices6.push( x, y, z );

                }
                
                for ( let i = 0; i < 10000; i ++ ) {

                    const x = 4000 * Math.random() - 1000;
                    const y = 2000 * Math.random() - 1000;
                    const z = 2000 * Math.random() - 1000;

                    vertices7.push( x, y, z );

                }



                geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
                geometry2.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices2, 3 ) );
                geometry3.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices3, 3 ) );
                geometry4.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices4, 3 ) );
                geometry5.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices5, 3 ) );
                geometry6.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices6, 3 ) );
                geometry7.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices7, 3 ) );




                material = new THREE.PointsMaterial( { size: 35, sizeAttenuation: true, map: sprite, alphaTest: 0.5, transparent: true } );
                material2 = new THREE.PointsMaterial( { size: 35, sizeAttenuation: true, map: sprite2, alphaTest: 0.5, transparent: true } );
                material3 = new THREE.PointsMaterial( { size: 35, sizeAttenuation: true, map: sprite3, alphaTest: 0.5, transparent: true } );
                material4 = new THREE.PointsMaterial( { size: 35, sizeAttenuation: true, map: sprite4, alphaTest: 0.5, transparent: true } );
                material5 = new THREE.PointsMaterial( { size: 35, sizeAttenuation: true, map: sprite5, alphaTest: 0.5, transparent: true } );
                material6 = new THREE.PointsMaterial( { size: 35, sizeAttenuation: true, map: sprite6, alphaTest: 0.5, transparent: true } );
                material7 = new THREE.PointsMaterial( { size: 35, sizeAttenuation: true, map: sprite7, alphaTest: 0.5, transparent: true } );
                
                


                

                const particles = new THREE.Points( geometry, material );
                scene.add( particles );
                
                const particles2 = new THREE.Points( geometry2, material2 );
                scene.add( particles2 );
                
                const particles3 = new THREE.Points( geometry3, material3 );
                scene.add( particles3 );
                
                const particles4 = new THREE.Points( geometry4, material4 );
                scene.add( particles4 );
                
                const particles5 = new THREE.Points( geometry5, material5 );
                scene.add( particles5 );
                
                const particles6 = new THREE.Points( geometry6, material6 );
                scene.add( particles6 );
                
                const particles7 = new THREE.Points( geometry7, material7 );
                scene.add( particles7 );

                //

                renderer = new THREE.WebGLRenderer();
                renderer.setPixelRatio( window.devicePixelRatio );
                renderer.setSize( window.innerWidth, window.innerHeight );
                document.body.appendChild( renderer.domElement );
                renderer.setClearColor( 0x000000);

                //

            

                //

                const gui = new GUI();

                gui.add( material, 'sizeAttenuation' ).onChange( function (){ 

                    material.needsUpdate = true;

                } );

                gui.close();

                //

                document.body.style.touchAction = 'none';
                document.body.addEventListener( 'pointermove', onPointerMove );

                //

                window.addEventListener( 'resize', onWindowResize );

            }

            function onWindowResize() {

                windowHalfX = window.innerWidth / 2;
                windowHalfY = window.innerHeight / 2;

                camera.aspect = window.innerWidth / window.innerHeight;
                camera.updateProjectionMatrix();

                renderer.setSize( window.innerWidth, window.innerHeight );

            }

            function onPointerMove( event ) {

                if ( event.isPrimary === false ) return;

                mouseX = event.clientX - windowHalfX;
                mouseY = event.clientY - windowHalfY;

            }

            //

            function animate() {

                requestAnimationFrame( animate );

                render();
                stats.update();

            }

            function render() {

                const time = Date.now() * 0.00000000005;

                camera.position.x += ( mouseX - camera.position.x ) * 0.05;
                camera.position.y += ( - mouseY - camera.position.y ) * 0.05;

                camera.lookAt( scene.position );

                const h = ( 360 * ( 1.0 + time ) % 360 ) / 360;
                

                renderer.render( scene, camera );

            }

        </script>

Thank you so much

Changing import to dynamic import

Could someone help me on rewriting below code to overcome the webpack issue.

Webpack issue Using externals as script generate unexpected code #12465


call-to-actions.ts

import { CallToActions as CallToActionsDb } from 'CallToActions.db';

//interface => ICallToAction
export interface ICallToAction {
    id: string;
    text: string;
    urlScheme: string;
}

//const => CallToActions
const CallToActions: Array<ICallToAction> = CallToActionsDb as Array<ICallToAction>;

//class => CallToActionUtil
export class CallToActionUtil {
    static toOptions(): Array<any> {

        let dropdownOptions: Array<any> = new Array<any>();

        for (let i = 0; i < CallToActions.length; i++) {
            let callToAction: ICallToAction = CallToActions[i];

            dropdownOptions.push({
                id: callToAction.id,
                text: callToAction.text,
                callToAction: callToAction
            });
        }

        return dropdownOptions;
    }
}

webpack.config

externals: {
'CallToActions.db': ['http://...', 'EsvTwBDKDf']
}

import image is not working in javascript

I am trying to import an image in javascript but don’t know why it not working infact it stop my whole javascript file from doing anything

import img from './image.png'
console.log(img)

It’s not showing anything in console not even any type of error and if I write more code below it that also don’t work.

Angular Making Headers Sticky

In my app, I have a screen with 3 tabs. Inside one of those tabs, there is a table and the table contains a large amount of rows. That’s why I want to make the headers of the table sticky. To be able to see the header names when I have to scroll down. I tried the approach below and nothing has changed. What should I do to make the headers sticky?

Main HTML:

    <mat-tab-group class="w-100-p" fxFill style="height:100vh;">
        <mat-tab>
            <ng-template mat-tab-label>
                <mat-icon class="mr-8">shopping_basket</mat-icon>
                Plan Çalışma Parametreleri
            </ng-template>
            <tab-material-plan-items [MaterialPlan]="materialPlan"
                [(MaterialPlanParameters)]="materialPlan.MaterialPlanParameters"
                [MaterialPlanId]="materialPlan.MaterialPlanId"></tab-material-plan-items>
        </mat-tab>
        <mat-tab>
            <ng-template mat-tab-label>
                <mat-icon class="mr-8">shopping_basket</mat-icon>
                Ürün/Reçete Bazlı Sonuçlar
            </ng-template>
            <tab-material-plan-receipt-result [MaterialPlan]="materialPlan"
                [(MaterialPlanReceiptResult)]="materialPlan.MaterialPlanReceiptResults"
                [MaterialPlanReceiptResultId]="materialPlan.MaterialPlanId"></tab-material-plan-receipt-result>
        </mat-tab>
    </mat-tab-group>

Tab HTML:

<form class="w-100-p" #workItemForm>
        <table mat-table matSort #table [dataSource]="dataSource" class="w-100-p" style="overflow: auto;">
            <ng-container matColumnDef="TotalOrderedQuantity">
                <th mat-header-cell *matHeaderCellDef mat-sort-header [ngStyle]="{'color': 'black'}" class="sticky" sticky>
                    <b>
                        Sipariş Edilen Miktar
                    </b>
                </th>
                <td mat-cell *matCellDef="let row; let i = index"
                    [ngStyle]="{'color':  row.TotalRequiredQuantity == 0 ? '#046307' : ' #E41B17'}">
                    <div>
                        {{row.TotalOrderedQuantity | number}}
                    </div>
                </td>
            </ng-container>
            <ng-container matColumnDef="TotalRequiredQuantity">
                <th mat-header-cell *matHeaderCellDef mat-sort-header [ngStyle]="{'color': 'black'}" class="sticky" sticky>
                    <b>
                        Planlanan İhtiyaç Miktarı
                    </b>
                </th>
                <td mat-cell *matCellDef="let row; let i = index"
                    [ngStyle]="{'color':  row.TotalRequiredQuantity == 0 ? '#046307' : ' #E41B17'}">
                    <div>
                        <b>
                            {{row.TotalRequiredQuantity | number}}
                        </b>
                    </div>
                </td>
            </ng-container>
            <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true" class="sticky"></tr>
            <tr mat-row *matRowDef="let row; columns: displayedColumns; let i = index"></tr>
        </table>
    </form>
    <mat-paginator [pageSizeOptions]="[10, 20, 50, 100]" class="sticky"></mat-paginator>

CSS:

.sticky {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
  }

Javascript when button is clicked is being colored while the other buttons lose their color

I have an rate app box,
I want the user to rate the app from 1-5 by clicking one of five buttons.

The button that was clicked should have color, all the others none.

So if he clicked first on 3 and then 2, when clicking on 2 the color from the 3 button will be removed so only the last button was clicked (in this case 2) will have a color.

I DID manage to do it using button array, but i know for sure there is shorter way that isnt involved button array, only by code inside the function.

html:

  <body>
  <div class="container">
    <div class="img-container">
      <img src="./images/icon-star.svg" alt="" class="img-star">
    </div>
    
    <div class="content">
      <h1>How did we do?</h1>
      <p id="content-paragraph"> 
      Please let us know how we did with your support request. All feedback is appreciated 
      to help us improve our offering!
      </p>
    </div>

    <div class="buttons-container">
      <button value = 1  class="choose " id="btn-one" onclick="paintBtn(this)">1</button>
      <button value = 2 class="choose" id="btn-two" onclick="paintBtn(this)">2</button>
      <button value = 3 class="choose" id="btn-three" onclick="paintBtn(this)">3</button>
      <button value = 4 class="choose" id="btn-four" onclick="paintBtn(this)">4</button>
      <button value = 5 class="choose" id="btn-five" onclick="paintBtn(this)">5</button>
    </div>
    <form action="thankYou.html">
      <button id="submit">SUBMIT</button>
    </form>

    <script src="index.js"></script>
</body

js:

const buttonOne = document.getElementById("btn-one")
const buttonTwo = document.getElementById("btn-two")
const buttonThree = document.getElementById("btn-three")
const buttonFour = document.getElementById("btn-four")
const buttonFive = document.getElementById("btn-five")

const buttonsArr = [buttonOne, buttonTwo, buttonThree, buttonFour, buttonFive]

function paintBtn(button) {
    buttonsArr.map(btn => btn.classList.remove("btn-clicked"))
   button.classList.add("btn-clicked")
  
}

enter image description here

Javascript element count in an array (based on a condition)

I am working on an LMS project where the end-user will click on a check box indicating a particular lesson is marked as complete. based on the number of lessons marked as completed, I need to showcase the percentage of course completion.

If there are 6 lessons and the user marked 3 lessons as completed, the math is 3/6 *100 = 50%.

Below is how my input JSON document looks like

[
    {
        "__typename": "ps_lessons",
        "lesson_id": 1,
        "id": "c9243c5b-2bf4-4afd-ab75-5fb7587b0d4f",
        "lesson_title": "Lesson 1",
        "multi_learners": [
            {
                "__typename": "ps_lesson_learners",
                "id": "5567c2a2-e0ff-4015-9bc6-a472b7683b01",
                "lesson_id": "c9243c5b-2bf4-4afd-ab75-5fb7587b0d4f",
                "check": true
            }
        ],
    },
    {
        "__typename": "ps_lessons",
        "lesson_id": 2,
        "id": "e3a26cc4-793e-4e56-bd30-c14a15633e5f",
        "lesson_title": "Lesson 2",
        "multi_learners": [
            {
                "__typename": "ps_lesson_learners",
                "id": "246e47e6-1821-4aae-9e2a-7abfd848ad4b",
                "lesson_id": "e3a26cc4-793e-4e56-bd30-c14a15633e5f",
                "check": true
            }
        ],
    },
    {
        "__typename": "ps_lessons",
        "lesson_id": 3,
        "id": "981e53c6-a63c-4a6f-84df-286c356b6a41",
        "multi_learners": [
            {
                "__typename": "ps_lesson_learners",
                "id": "52f44453-eb6a-4694-ba38-cfb6f96ab50d",
                "lesson_id": "981e53c6-a63c-4a6f-84df-286c356b6a41",
                "check": false
            }
        ],
    },
    {
        "__typename": "ps_lessons",
        "lesson_id": 4,
        "id": "88a7c331-0029-451e-b408-d35fbfd8f3f9",

    },
      {
        "__typename": "ps_lessons",
        "lesson_id": 5,
        "id": "88a7c331-0029-451e-84df-286c356b6a41",
    }
    
]

in the above document there are a total of 5 ps_lessons elements are there for every element there is a sub-element ps_lesson_learners where multi_learners[0].check indicates the user’s selection.

So I need to figure it out, if there is a subelement i.e. ps_lesson_learners if the subelement is present then check the true value for multi_learners[0].check and divide it with the total lessons and multiply by 100 to get the percentage.

there are a total of 2 true status out of 5 lessons so it will be 2/5 * 100 = 40%

I tried some thing like below with map method and coudln’t able to get the result

  data.map((data)=>{
    if (data.multi_learners.length == 1) {
      if (data.multi_learners[0].check == 'true') {
        count = count + 1;
      }
    }
  });

  final_count = count * data.length/100

Appreciate your help with the code.

Thanks
Venk