0

I have a list of Array with filenames and filepath. Is group into a list of array.

Example :

**var files = [filenameA, filenameB, filenameC, filepathA, filepathB, filepathC]**

I need to map them and convert them to -->

var remapfiles = {[filenameA,filepathA],[filenameB,filepathB], [filenameC,filepathC]}

The reason it was compile in files it was extracted using an SDK function where it will retrieve all filesnames and path.

How should i map/sort this to get remapfiles result and to log ? Please advice.

MavDev
  • 3
  • 1
  • can you show a sample of `filenameA` and `filepathA`? you can use reduce to do this – boxdox Aug 23 '21 at 09:34
  • Hi@boxdox, this is the sample of path '"FileA.xlsm,FileB.xlsm,FileC .xlsm,C:\\Bla\\Bla\\EXCEL_FOLDER\\FileA.xlsm,C:\\Bla\\Bla\\EXCEL_FOLDER\\FileB.xlsm,C:\\Bla\\Bla\\EXCEL_FOLDER\\FileC.xlsm,' – MavDev Aug 23 '21 at 11:16

2 Answers2

0

Assuming filepaths always come after filenames, you can try:

let files = ['filenameA', 'filenameB', 'filenameC', 'filepathA', 'filepathB', 'filepathC']
let remapfiles = [];
for (let i = 0; i < files.length/2; i++) {
  remapfiles.push([files[i], files[files.length/2+i]])
}
console.log(remapfiles)
TYeung
  • 2,579
  • 2
  • 15
  • 30
  • Thanks! it works but there's slight changes need to handle increasing of files. `code` let files = ['filenameA', 'filenameB', 'filenameC', 'filepathA', 'filepathB', 'filepathC'] let remapfiles = []; for (let i = 0; i < files.length/2; i++) { remapfiles.push([files[i], files[files.length/2+i]]) } console.log(remapfiles) `code` – MavDev Aug 23 '21 at 11:18
0

Thanks to @Learning Mathematics

let files = ['filenameA', 'filenameB', 'filenameC', 'filepathA', 'filepathB', 'filepathC']
let remapfiles = [];
for (let i = 0; i < files.length/2; i++) {
  remapfiles.push([files[i], files[files.length/2+i]])
}
console.log(remapfiles)

This code works.

MavDev
  • 3
  • 1