gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
Generate html webpage with javascript code to read a csv and find duplicates provided a…
- User
Generate html webpage with javascript code to read a csv and find duplicates provided a column name. Generate only code without any extra content. The generated code should be production ready and runnable immediately.
- Assistant
// Function to find duplicates in the specified column function findDuplicates(columnName, csvData) { let duplicates = []; let csvRows = csvData.split('\n'); let headers = csvRows[0].split(','); for (let i = 1; i < csvRows.length; i++) { let rowData = csvRows[i].split(','); let columnIndex = headers.indexOf(columnName); let columnValue = rowData[columnIndex].trim(); for (let j = i + 1; j < csvRows.length; j++) { let nextRowData = csvRows[j].split(','); let nextColumnValue = nextRowData[columnIndex].trim(); if (columnValue === nextColumnValue && !duplicates.includes(columnValue)) { duplicates.push(columnValue); } } } return duplicates; } // Function to handle file input change function handleFileInputChange(event) { let file = event.target.files[0]; readCSV(file) .then(csvData => { let columnName = "column_name"; // Replace with the desired column name let duplicates = findDuplicates(columnName, csvData); console.log(duplicates); // Print the duplicates (you can modify this to display the results on the webpage instead) }) .catch(error => { console.error('Error reading the file:', error); }); } // Attach event listener to file input element $('#fileInput').on('change', handleFileInputChange); }); </script>
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.