javascript – Data can’t be Filter using Node js

I am trying to filter out empty array but its not happening

  • I was trying to compare value which are present inside my database and fileName
  • I tried arr.filter(Boolean);
  • even i tried
  • List item arr.filter((item)=>item)

PS: fileName is not an array value so I converted it into array.

function checkDoc(data, childProduct, fileName, pathName, req, res) {
  return new Promise((resolve, reject) => {
    Document.findAll({
      raw: true,
      where: {
        product_id: childProduct.id,
      },
    })
      .then((productDoc) => {
        if (productDoc.length === 0) {
          return resolve(addDocument(data, childProduct, fileName, pathName));
        } else {
          let fileArray = ();
          fileArray.push(fileName);
          productDoc.forEach((singleProduct) => {
            let productValue = singleProduct.name;
            let unMatchedValues = fileArray.filter((value) =>
              productValue.includes(value)
            );
            let removedBoolean = unMatchedValues.filter((item) => item);
            console.log("Document Name: ", removedBoolean);
          });
        }
      })
      .catch(function (err) {
        return reject("Can't be added please try again :) " + err);
      });
  });
}

attached Output Image :

enter image description here

javascript – Given a MxN array compress it by merging duplicates along the rows and columns

The code as follows

var input =  ((1,2,3,4,5), (1,2,3,4,5), (1,2,6,7,8), (1,1,1,7,8), (1,2,1,7,9));

function Compress(args){

// Code goes here

}

var outputStr = Compress(input)

The sample input is as follows

input

and output should be like

output_1

OR
like this

outout_2

SQL function on a javascript variable

I have a javascript file that receives a number like “1345”, and in order to insert it into a table, I need to find a way to apply an specifiq SQL command on it.

This is the code that I have:

var stime = traffic.startTime;
var dateNow = new Date().toLocaleString('pt-BR', {
            timeZone: "America/Sao_Paulo"
        });

conn.executeUpdate(
            'INSERT INTO "SCHEMA"."TABLE" VALUES (?,?,?,?,?,?,?,?,?)',
            val1, val2, val3, val4, stime, val6, val7, new Date(dateNow), null);

what I need is to apply the SQL function to_time to the variable stime and then, run the insert. so to_time(stime, HHMI).

How can I do that?

Obs: I don’t wanna manipulate the number in js, it’s gotta be in SQL.

bucle for – ¿Como modificar el nombre de una variable? Javascript

Tengo un problema con un ejercicio planteado por mi profesor
Me indica que quiere que haga un loop para crear 30 objetos diferentes de manera automatica
Pero al momento de usar la funcion creadora new, me encuentro con un problema
Se reescribe el valor 30 veces sobre la misma variable asignada a la funcion constructora
Y no encuentro la manera de por medio de algun codigo dentro del loop, que se reescriba al reiniciarse el loop el nombre de la variable.

function tests(a,b,c){
    this.a = a;
    this.b = b;
    this.c = c;
}
function datos (){
    var azar = Math.floor(Math.random()*100);
    return azar;
}
function datos2 (){
    var azar = Math.floor(Math.random()*100);
    return azar;
}
function datos3 (){
    var azar = Math.floor(Math.random()*100);
    return azar;
}
    for(var i = 0, x=30 ; i < x; i++){
        var usuario = "usuario"+i;
        nombre = datos3();
        informacion = datos2 ();
        determinante = datos ();
            var usuario = new tests(determinante,informacion,nombre);
            console.log("Primera etapa");
            console.log(usuario);
        }
    

tengo los console.log para tener una retroalimentacion de que esta ocurriendo cuando lo ejecuto en la consola.

javascript – Setear value de un input radio a un input text vacio

Quiero pasar el value de un input radio seleccionado en un modal, a un input text vacio que tengo en un formulario.

Radio del modal:

        <div class="img-user-profile">
            @foreach($files as $image)
                <label class="checkeable">
                    <input type="radio" id="image-profile-radio" name="image-profile" value="{{'images/user-profile/'.$image->getRelativePathname()}}"/>
                    <img src="{{asset('images/user-profile/'.$image->getRelativePathname()) }}">
                </label>
            @endforeach

 <button id="confirm-image-profile" class="btn btn-primary btn-block joinOnlineEventButton">
 Confirm selection
 </button>

Lo quiero guardar en este campo del formulario del cual se abre el modal.

                <div class="hide">
                    <input type="text" class="input-image-random" name="input-image-random" id="input-image-random" value="">

                </div>

He probado con estas dos funciones, pero no logro que se quede guardado en el value del input text:

$("#confirm-image-profile").click(function() {
    $("#confirm-image-profile").click(function() {
        $("input(name='image-profile')").change(function(){
            $("#input-image-random").val($("input(name='image-profile'):checked").val());
        });
    });
});

$("#confirm-image-profile").click(function() {
    let imageProfile = $("input(name='image-profile'):checked").val();
    let imagenProfileForm = imageProfile;
    console.log(imagenProfileForm + ' a')
    console.log(imageProfile)
    $('#show-upload-user-photo').modal('hide');

});

¿Alguien me puede ayudar a guardar ese valor ahí?

javascript – setting start scripts to start app on heroku

I have a React / node app that I took over and that I am trying to push to heroku.

I use the following commands to start my app locally:

cd react-web
sudo npm run postinstall
export REACT_APP_CUSTOMER_ENVIRONMENT=testenv
npm start

so, this starts the app. Now for heroku, in my root directory package.json, I have this start script:

    "scripts": {
    "test-web": "cd react-web && npm test && cd ..",
    "test": "npm run test-web",
    "start": "cd react-web && npm run postinstall && export REACT_APP_CUSTOMER_ENVIRONMENT= testenv && npm start"
  },

and then in my react-web package.json, I have this:

 "scripts": {
    "start": "node checkEnvironmentForBuild && react-app-rewired start",
    "build": "node checkEnvironmentForBuild && react-app-rewired build",
    "deploy": "aws s3 sync build/ s3://YOUR_S3_DEPLOY_BUCKET_NAME --delete",
    "postdeploy": "aws cloudfront create-invalidation --distribution-id YOUR_CF_DISTRIBUTION_ID --paths '/*' && aws cloudfront create-invalidation --distribution-id YOUR_WWW_CF_DISTRIBUTION_ID --paths '/*'",
    "postinstall": "npm link ../shared",
    "test": "node checkEnvironmentForBuild && react-app-rewired test",
    "eject": "react-scripts eject"
  },

in my Procfile, I have this:

web: npm start

when I push to heroku, in the logs, I receive the H12 timeout error. It basically says it is failing with the start scripts.

anyone know what my problem could be

javascript – Datatable redimensionar columnas arrastrando

compañeros tengo un inconveniente, los pongo al tanto, estoy trabajando en una vista donde el usuario tiene varios filtros que una vez consultados llenan una tabla, hay campos que se extienden mucho y me solicitan que en vez de ocultar los campos los pueda re-dimensionar arrastrando el borde de la columna, como en un excel, intente hacerlo con este plugin https://github.com/dobtco/jquery-resizable-columns, pero no lo he podido integrar de manera correcta, manejo bootstrap en version 4.3 y jquery en versión 3.3, manejo una plantilla de cabecera y otra de pie de pagina, pero aun así no función, conocen alguna manera que pueda funcionarme?
Header

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="description" content="Herramienta de control de estanteria">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="author" content="Edison Salguero 3133328856">
  <meta name="theme-color" content="#009688">
  <link rel="shortcut icon" href="<?= media();?>/images/favicon.ico"> <!-- Para cambiar el icono de la pestaña -->
  <title><?= $data('tag_page')?></title>
  <!-- Main CSS-->
  <link rel="stylesheet" type="text/css" href="<?= media();?>/css/main.css">
  <link rel="stylesheet" type="text/css" href="<?= media();?>/css/bootstrap-select.min.css">
  <link rel="stylesheet" type="text/css" href="<?= media();?>/css/style.css">
  <!-- <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"> -->
  <link rel="stylesheet" href="<?= media();?>/css/jquery.resizableColumns.css">
</head>
<body class="app sidebar-mini">
  <!-- Navbar-->
  <header class="app-header"><a class="app-header__logo" href="<?= baseUrl();?>/Dashboard"><img src="<?= media(); ?>/images/Logo.png" alt=""></a>
    <!-- Sidebar toggle button--><a class="app-sidebar__toggle" href="#" data-toggle="sidebar" aria-label="Hide Sidebar"></a>
    <!-- Navbar Right Menu-->
    <ul class="app-nav">
      <!-- User Menu-->
      <li class="dropdown"><a class="app-nav__item" href="#" data-toggle="dropdown" aria-label="Open Profile Menu"><i class="fa fa-user fa-lg"></i></a>
        <ul class="dropdown-menu settings-menu dropdown-menu-right">
          <!-- <li><a class="dropdown-item" href="<?= baseUrl();?>/Opciones"><i class="fa fa-cog fa-lg"></i> Settings</a></li>
          <li><a class="dropdown-item" href="<?= baseUrl();?>/Perfil"><i class="fa fa-user fa-lg"></i> Profile</a></li> -->
          <li><a class="dropdown-item" href="<?= baseUrl();?>/Logout"><i class="fa fa-sign-out fa-lg"></i> Logout</a></li>
        </ul>
      </li>
    </ul>
  </header>
  <?php require_once("Nav_admin.php");?>

main

<?php HeaderAdmin($data); ?>
<main class="app-content">
    <?php //getModal('modalAdministrativo',$data); 
        if (empty($_SESSION('permisosmod')('R'))) {
    ?>
    <p>Acceso Restringido</p>
    <?php 
        }else{ ?>
    <div class="app-title">
        <div>
            <h1><i class="fas fa-boxes"></i> <?= $data('tittle_page');?></h1>
            <?php if ($_SESSION('permisosmod')('W')){ ?>
            <!-- <button class="btn btn-primary" type="button" onclick="openModal();">Nuevo <i class="fas fa-plus-circle"></i></button> -->
            <?php }?>
            <a href="<?= baseUrl(); ?>/Administrativo">Filtros de busqueda<i class="fas fa-search"></i></a>
        </div>
        <ul class="app-breadcrumb breadcrumb">
            <li class="breadcrumb-item"><a href="<?= baseUrl(); ?>"><i class="fa fa-home fa-lg"></i></a></li>
            <li class="breadcrumb-item"><a href="<?= baseUrl(); ?>/Administrativo">Base Administrativa</a></li>
        </ul>
    </div>
    <div class="tile" id="filtrosadmin">
        <div id="divLoading">
            <div>
                <img src="<?= media(); ?>/images/loader.svg" alt="Loading">
            </div>
        </div>
        <ul class="nav nav-tabs" id="myTab" role="tablist">
          <li class="nav-item" role="presentation">
            <a class="nav-link active" id="iIdCaja-tab" data-toggle="tab" href="#iIdCaja" role="tab" aria-controls="iIdCaja" aria-selected="true">iIdCaja</a>
          </li>
          <li class="nav-item" role="presentation">
            <a class="nav-link" id="CajaN-tab" data-toggle="tab" href="#CajaN" role="tab" aria-controls="CajaN" aria-selected="true">iIcajaNum</a>
          </li>
          <li class="nav-item" role="presentation">
            <a class="nav-link" id="Caja-tab" data-toggle="tab" href="#Caja" role="tab" aria-controls="Caja" aria-selected="true">CAJA </a>
          </li>
          <li class="nav-item" role="presentation">
            <a class="nav-link" id="IdCAL-tab" data-toggle="tab" href="#IdCAL" role="tab" aria-controls="IdCAL" aria-selected="true">ID CARP-AZ-LIBRO</a>
          </li>
          <li class="nav-item" role="presentation">
            <a class="nav-link" id="iIdent-tab" data-toggle="tab" href="#iIdent" role="tab" aria-controls="iIdent" aria-selected="true">iIdentificacion</a>
          </li>
          <li class="nav-item" role="presentation">
            <a class="nav-link" id="tObs-tab" data-toggle="tab" href="#tObs" role="tab" aria-controls="tObs" aria-selected="true">tObservac</a>
          </li>
          <li class="nav-item" role="presentation">
            <a class="nav-link" id="Fini-tab" data-toggle="tab" href="#Fini" role="tab" aria-controls="Fini" aria-selected="true">Fecha inicial</a>
          </li>
          <li class="nav-item" role="presentation">
            <a class="nav-link" id="Ffin-tab" data-toggle="tab" href="#Ffin" role="tab" aria-controls="Ffin" aria-selected="true">Fecha final</a>
          </li>
          <li class="nav-item" role="presentation">
            <a class="nav-link" id="Ttfin-tab" data-toggle="tab" href="#Ttfin" role="tab" aria-controls="Ttfin" aria-selected="true">tTipoFinal</a>
          </li>
        </ul>
        <div class="tab-content" id="myTabContent">
            <div class="tab-pane fade show active" id="iIdCaja" role="tabpanel" aria-labelledby="iIdCaja-tab">
                <div class="tile">
                    <div class="card border-light mb-3 mx-auto" style="max-width: 50rem;">
                        <div class="card-header text-primary">Busqueda por Id de Caja</div>
                        <div class="card-body">             
                            <form name="formId" id="formId" action="" >
                                <textarea class="form-control" placeholder="Ingrese el/los Id de caja" id="IdC" name="IdC" required></textarea>
                                <br>
                                <p><input type="submit" class="btn btn-outline-primary" /></p>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            <div class="tab-pane fade" id="CajaN" role="tabpanel" aria-labelledby="CajaN-tab">
                <div class="tile">
                    <div class="card border-light mb-3 mx-auto" style="max-width: 50rem;">
                        <div class="card-header text-info">Busqueda por Caja Numero</div>
                        <div class="card-body">             
                            <form name="formCN" id="formCN" action="" >
                                <textarea class="form-control" placeholder="Ingrese el/los caja numero" id="NC" name="NC" required></textarea>
                                <br>
                                <p><input type="submit" class="btn btn-outline-info" /></p>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            <div class="tab-pane fade" id="Caja" role="tabpanel" aria-labelledby="Caja-tab">
                <div class="tile">
                    <div class="card border-light mb-3 mx-auto" style="max-width: 50rem;">
                        <div class="card-header text-success">Busqueda por Caja</div>
                        <div class="card-body">             
                            <form name="formCa" id="formCa" action="" >
                                <textarea class="form-control" placeholder="Ingrese la/s caja/s" id="Ca" name="Ca" required></textarea>
                                <br>
                                <p><input type="submit" class="btn btn-outline-success" /></p>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            <div class="tab-pane fade" id="IdCAL" role="tabpanel" aria-labelledby="IdCAL-tab">
                <div class="tile">
                    <div class="card border-light mb-3 mx-auto" style="max-width: 50rem;">
                        <div class="card-header text-dark">Busqueda por Id de carpeta/azeta/libro</div>
                        <div class="card-body">             
                            <form name="formcal" id="formcal" action="" >
                                <textarea class="form-control" placeholder="Ingrese el/los Id a consultar" id="Cal" name="Cal" required></textarea>
                                <br>
                                <p><input type="submit" class="btn btn-outline-dark" /></p>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            <div class="tab-pane fade" id="iIdent" role="tabpanel" aria-labelledby="iIdent-tab">
                <div class="tile">
                    <div class="card border-light mb-3 mx-auto" style="max-width: 50rem;">
                        <div class="card-header text-danger">Busqueda por Identificación</div>
                        <div class="card-body">             
                            <form name="formiId" id="formiId" action="" >
                                <textarea class="form-control" placeholder="Ingrese el/los Id a consultar" id="iId" name="iId" required></textarea>
                                <br>
                                <p><input type="submit" class="btn btn-outline-danger" /></p>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            <div class="tab-pane fade" id="tObs" role="tabpanel" aria-labelledby="tObs-tab">
                <div class="tile">
                    <div class="card border-light mb-3 mx-auto" style="max-width: 50rem;">
                        <div class="card-header text-dark">Busqueda por observaciones</div>
                        <div class="card-body">             
                            <form name="formObs" id="formObs" action="" >
                                <textarea class="form-control" placeholder="Ingrese la frase a buscar o una palabra clave" id="obs" name="obs" required></textarea>
                                <br>
                                <p><input type="submit" class="btn btn-outline-dark" /></p>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            <div class="tab-pane fade" id="Fini" role="tabpanel" aria-labelledby="Fini-tab">
                <div class="tile">
                    <div class="card border-light mb-3 mx-auto" style="max-width: 50rem;">
                        <div class="card-header text-success">Busqueda por Fecha Inicial</div>
                        <div class="card-body">             
                            <form name="formFini" id="formFini" action="" >
                                <input type="text" class="form-control" id="fini" name="fini" placeholder="dd/mm/aaaa" required>
                                <p class="card-text"><small class="text-muted">Digite la fecha por la que desea consultar separado por "/"</small></p>
                                <br>
                                <p><input type="submit" class="btn btn-outline-success" /></p>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            <div class="tab-pane fade" id="Ffin" role="tabpanel" aria-labelledby="Ffin-tab">
                <div class="tile">
                    <div class="card border-light mb-3 mx-auto" style="max-width: 50rem;">
                        <div class="card-header text-info">Busqueda por Fecha Final</div>
                        <div class="card-body">             
                            <form name="formFin" id="formFin" action="" >
                                <input type="text" class="form-control" id="ffin" name="ffin" placeholder="dd/mm/aaaa" required>
                                <p class="card-text"><small class="text-muted">Digite la fecha por la que desea consultar separado por "/"</small></p>
                                <br>
                                <p><input type="submit" class="btn btn-outline-info" /></p>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            <div class="tab-pane fade" id="Ttfin" role="tabpanel" aria-labelledby="Ttfin-tab">
                <div class="tile">
                    <div class="card border-light mb-3 mx-auto" style="max-width: 50rem;">
                        <div class="card-header text-primary">Busqueda Tipo Final</div>
                        <div class="card-body">             
                            <form name="formtT" id="formtT" action="" >
                                <textarea class="form-control" placeholder="Ingrese el tipo final a consultar o una palabra clave" id="tTf" name="tTf" required></textarea>
                                <br>
                                <p><input type="submit" class="btn btn-outline-primary" /></p>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- tabla de base administrativa -->
    <div class="row" id="tabla">
      <div class="col-md-12">
        <div class="tile">
          <div class="tile-body">
            <div class="table-responsive">
              <table class="table table-bordered display pre" data-resizable-columns-id="demo-table-v2" cellpadding="0" width="100%" id="tableAdmin">
                <thead>
                  <tr>
                    <th data-resizable-column-id="Novedad">Novedad</th>
                    <th>Base Consolidada</th>
                    <th>Tentrega</th>
                    <th>Tpaquete</th>
                    <th>Iidcaja</th>
                    <th>Iicajanum</th>
                    <th>Caja</th>
                    <th>Serie</th>
                    <th>Id Carp-Az-Libro</th>
                    <th>Iidentificacion</th>
                    <th>Ifecha</th>
                    <th>Tobservac</th>
                    <th>Fecha Inicial</th>
                    <th>Fecha Final</th>
                    <th>Ttipofinal</th>
                    <th>Tomo</th>
                    <th>Folios</th>
                    <th>Mg</th>
                    <th>Tobservac</th>
                    <th>Adiciones</th>
                    <th>Unidad Contenedora</th>
                    <th>Piso</th>
                    <th>Linea</th>
                    <th>Modulo</th>
                    <th>Ubicacion</th>
                    <th>Accion</th>
                  </tr>
                </thead>
                <tbody>

                </tbody>
              </table>
              <script src="<?= media();?>/js/jquery.resizableColumns.min.js"></script>
              <script>
                $(function(){
                  $("table").resizableColumns({
                    store: window.store
                  });
                });
              </script>
            </div>
          </div>
        </div>
      </div>
    </div>
<?php } ?>
</main>
<?php FooterAdmin($data); ?>

Footer

 <script>
        const baseUrl = "<?= baseUrl();?>";
    </script>
    <!-- Essential javascripts for application to work-->
    <script src="<?= media();?> /js/jquery-3.3.1.min.js"></script>
    <script src="<?= media();?>/js/plugins/chart.js"></script>
    <script src="<?= media();?>/js/plugins/chartjs-plugin-datalabels.js"></script>
    <script src="<?= media();?> /js/popper.min.js"></script>
    <script src="<?= media();?> /js/bootstrap.min.js"></script>
    <script src="<?= media();?> /js/main.js"></script>
    <script src="<?= media();?> /js/Fontawesome.js"></script>
    <!-- The javascript plugin to display page loading on top-->
    <script src="<?= media();?> /js/plugins/pace.min.js"></script>
    <!-- Data table plugin-->
    <script type="text/javascript" src="<?= media();?>/js/plugins/bootstrap-select.min.js"></script>
    <script type="text/javascript" src="<?= media();?>/js/plugins/jquery.dataTables.min.js"></script>
    <script type="text/javascript" src="<?= media();?>/js/plugins/dataTables.bootstrap.min.js"></script>
    
    <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/1.5.2/js/dataTables.buttons.min.js"></script>
    <script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
    <script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
    <script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
    <script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.html5.min.js"></script>

    <script src="<?= media();?>/js/<?= $data('functions_js_page');?>"></script>
    <!-- Page specific javascripts-->
    <script type="text/javascript" src="<?= media();?> /js/plugins/sweetalert.min.js"></script>
  </body>
</html>

pantalla

javascript – List sub-folders and its ID in the given path in Google Drive with Google App Script

I am trying to create a doc file which contains the list of folders in a given folder path. The Main function is the entry point.

// This function performs the operation of creating the file of the list of folders in the specific folder.
// Usage: Set the ListDocName, the ListDocFullPath, and the SpecificFolder, then just run Main function.
function Main() {
  // Set Doc (output) file name
  var ListDocName = "RootFolderList";
  
  // Set Doc (output) file path
  var ListDocFullPath = "/";
  
  // Set specific folder, and this program would list its subfolders to Doc file.
  var SpecificFolder = "/";
  
  CreateGoogleDocInSpecificFolder(ListDocName, ListDocFullPath);
  var DocFiles = GoogleDocsInSpecificFolder(ListDocName, ListDocFullPath);
  
  while(DocFiles.hasNext())
  {
    var docFile = DocFiles.next();
    var docID = docFile.getId();
    var doc = DocumentApp.openById(docID);
    
    var Folders = FoldersInSpecificFolder(SpecificFolder);
    while(Folders.hasNext())
    {
      var Folder = Folders.next();
      // Access the body of the document, then add a paragraph.
      doc.getBody().appendParagraph(SpecificFolder + "https://codereview.stackexchange.com/" + Folder.getName() + 't' + Folder.getId());
    }
    doc.saveAndClose();
  }
}

// FoldersInSpecificFolder function would return a FileIterator
function FoldersInSpecificFolder(FolderFullPath)
{
  if(FolderFullPath == "https://codereview.stackexchange.com/")
  {
    // Return the FolderIterator in Root.
    return getFolder(FolderFullPath);
  }
  else
  {
    // getFolder return the FolderIterator
    var TargetFolders = getFolder(FolderFullPath);
    while (TargetFolders.hasNext())
    {
      var folder = TargetFolders.next();
      return folder.getFolders();
    }
  } 
}

// GoogleDocsInSpecificFolder function would return a FileIterator
function GoogleDocsInSpecificFolder(docName, FolderFullPath)
{
  if(FolderFullPath == "https://codereview.stackexchange.com/")
  {
    // Read files in Root, getFilesByName return the FileIterator
    var RootDocs = DriveApp.getRootFolder().getFilesByName(docName);
    return RootDocs;
  }
  else
  {
    // getFolder return the FolderIterator
    var TargetFolders = getFolder(FolderFullPath);   
    while (TargetFolders.hasNext())
    {
      var folder = TargetFolders.next();
      var docFiles = folder.getFilesByName(docName);
      return docFiles;
    }
  } 
}

function CreateGoogleDocInSpecificFolder(docName, FolderFullPath)
{
  var docID;
  if(FolderFullPath == "https://codereview.stackexchange.com/")
  {
    // Create a new Google Doc in Root
    var docRoot = DocumentApp.create(docName);
    var docRootID = docRoot.getId();
    docRoot.saveAndClose();
    return docRootID;
  }
  else
  {
    // Create a new Google Doc in Root
    var docRoot = DocumentApp.create(docName);
    var docRootID = docRoot.getId();
    docRoot.saveAndClose();
    
    // Get new Google Doc file ID (Use in copy)
    var docRootFile = DriveApp.getFileById(docRootID);
    
    var TargetFolders = getFolder(FolderFullPath);   
    while (TargetFolders.hasNext())
    {
      var folder = TargetFolders.next();
      
      // Copy Google Doc to correct file path
      var docFile = docRootFile.makeCopy(docName, folder);
      
      docID = docFile.getId();
    }
    
    // Delete Google Doc in Root
    DriveApp.removeFile(docRootFile);
    
    return docID;
  } 
}

// getFolder function would return the FolderIterator which is locate at Path.
function getFolder(Path)
{
  var SubFolder;
  var arr = Path.split("/");
  for (var i = 1; i < arr.length; i = i + 1)
  {
    var FolderName = arr(i);
    if(i == 1)
    {
      SubFolder = DriveApp.getRootFolder().searchFolders("title contains '"+FolderName+"'");
    }
    else
    {
      if (SubFolder.hasNext())
      {
        var folderTemp = SubFolder.next();
        SubFolder = folderTemp.searchFolders("title contains '"+FolderName+"'");
      }
    }
  }
  return SubFolder;
}

If there is any possible improvement about potential drawback, please let me know.

javascript – webp picture format and fallback techniques

I want to build a community website where people can upload pictures and give comments and such things.
I have heard about webp picture format: it can help to load pictures faster because mostly the pictures’ file size will be smaller.

I am using node.js and Javascript and I want to search now for a script for picture upload, I think it will not be so complicate to find something for picture upload and also transfer picture to webp format.

But I ask myself what to do if a browser does not support that format, i have hear that you need to code a fallback in that case and give the browser jpg format, but this would also mean that I need from every picture a webp format and a jpg format, or how is this usually done?

javascript – same object in res.json

I am using res.json().

I have an object

let message =

{
  abc: {
    aplha: 'num'
  }
}

Now I am doing res.json(message)

From this the response I am getting like this:

 message: { 
    {
      abc: {
        aplha: 'num'
      }
    }
 }

But I want the response like this:

      abc: {
        aplha: 'num'
      }

How can I do that?