score:0
Accepted answer
const tokens = input.split(/\s+/g);
const output = [["period end", "date", "full name", "hours", "tracking name", "totalhours", "task 1 hours", "task 2 hours", "task 3 hours", "task 4 hours", "task 5 hours", "task 6 hours", "task 7 hours", "task 8 hours"]];
for (let origin = 0, index = 0; index < tokens.length; index++) {
// find date range
if (tokens.slice(index, index + 3).join(" ").match(/\d{1,2}\/\d{1,2}\/\d{4} - \d{1,2}\/\d{1,2}\/\d{4}/g)) {
if (origin !== 0) {
output.push([tokens.slice(origin, origin + 3).join(" "), ...tokens.slice(origin + 3, index)]);
}
origin = index;
index += 2;
}
}
for (const row of output) {
// i get to be lazy, you have to use a library.
console.log(row.join(","));
}
edit: i realized that this isn't actually capturing the last line of data, but i didn't want to rely on a fixed token-width for rows, so i'll leave it as an exercise for the reader to determine when you want the last line to end.
Source: stackoverflow.com
Related Query
- How to convert this data to csv using Nodejs/ JavaScript
- How to update elements of an HTML that the elements are created using data from a CSV file?
- Using Javascript D3 library, how can I determine mouse position in data set of an area element on mousemove event?
- How would I import a single column CSV file into a pie chart using Javascript D3?
- How to iterate over data in JSON file using D3 javascript
- Using Javascript D3 library, how replace data in selection of rects?
- In a d3 scatterplot using data from a csv file, how do i draw lines connecting related points when the mouse is over a point?
- In d3.js, while importing csv files using a row conversion, how can I "slice" the data to only include a range of rows?
- how to convert data selected from a postgres database to json or csv to use it with d3js lib?
- how to get data from mongodb and display as a d3 chart using nodejs
- How to convert D3 data array-of-objects from long-format to wide-format in JavaScript and D3?
- How do I access CSV data using d3.js
- How to update data on a page according to data from a CSV file instead of using fixed element data on the page?
- How to create a multiseries line chart using data filtered from a csv file?
- How can I parse csv data from a javascript array of strings for use in d3 graphs
- How to convert CSV Data to JSON Object
- D3js: How to load CSV data and convert it into nvd3.js object?
- Extracting data from excel sheet into csv (or) Json using Javascript
- How do I retrieve an array from a csv file in javascript using d3?
- How can you access data that's nested like this in a csv file?
- How to instantiate scala.scalajs.js.ThisFunction3 in this example using org.singlespaced.d3js' data function
- How can create a table with using filter on csv data
- unable to read data from a CSV file using javascript
- Using crossfilter with dc.js and d3.js - how to get csv year data into date format?
- How to load data from a CSV file in D3 v5
- How do I convert a JavaScript forEach loop/function to CoffeeScript
- Select data from a CSV before loading it with javascript (d3 library)
- how to encode this data to parent / children structure in JSON
- How to import XML data using d3.js?
- How do I create a tree layout using JSON data in d3.v4 - without stratify()
More Query from same tag
- How to convert latitude longitude to azimuth coordinates for d3.js?
- d3: Append caption/title to table
- d3.js dynamically generated sentence map with curved text
- D3js V4 Center Node in Zoomable Tree
- D3 adding donut chart within a tooltip
- How to implement Javascript within Salesforce Visual Force?
- Using D3.select to change the thickness of text in a radial dendrogram with a mouseover
- How to zoom a d3.js DotsChart instead of lineChart
- Using d3 instead of jQuery to process form input causes re-load of "/"
- d3.bisector on descending array
- How to remove axis line overflow in c3js line graph
- Selecting multiple dom elements by index with d3.selectAll()
- D3 color selector using directive scope returns always first color
- Error encountered when building composite chart dc.js
- text-anchor don't appear in D3
- Tooltips not working on the initial plot but start working once the plot changes
- Typescript typecast with D3.js
- How to cancel scheduled transition in d3?
- Select divs by ID prefix in d3
- CSV/TSV comment lines d3
- nvd3 pie outerRadius
- Forced Directed graph multiple edges using d3 canvas
- Data structure returned by d3.csvParse
- D3.js - Animated exit for nested object
- random colors for circles in d3.js graph
- Displaying charts with D3.js
- Dropping balls in Javascript, not dropping one by one, instead all the balls dropped at once. (must be related to 'iterator')
- D3.js, multiply element <g>
- D3 - redraw SVG after DOM change
- How to get target element in drag n drop d3 v4?