<commit_before>function TableConversions(){};

/**
 * Convert an object (or more typically an Array of objects) into a Table
 * @param {Object} object or array of objects
 *
 * @param {List} list of field names to include (by default will take all from first element in array of objects)
 * @return {Table} resulting Table
 * tags:decoder,dani
 */
TableConversions.ObjectToTable = function(object, fields){
	// Formats:
	// 1: normal list of objects
	// 2: Object with single property, containing normal list of obejcts
	// 3: Object as CSV (each property represents a column)
	var format;

	// If it's an array, then it's format 1
	if( Array.isArray(object) ){
		format = 1;
		// If not field names supplied, get them from first element
		if( !fields )
		{
			fields = [];
			for( var p in object[0] ){
				fields.push( p );
			}
		}
	// Else (not array), it's an object
	}else{
		// Check how many properties the object has
		var properties = [];
		for( var p in object ){
			properties.push( p );
		}

		// If it has only one, and it's an array, it's foramt 2, so assume it's just a capsule
		// and extract the array as format 1
		if( properties.length == 1 && Array.isArray( object[properties[0]] ) )
		{
			format = 1;
			object = object[properties[0]];

			// If not field names supplied, get them from first element
			if( !fields )
			{
				fields = [];
				for( var p in object[0] ){
					fields.push( p );
				}
			}
		}else{
			// Finally, if the object has many properties, we assume it's a csv encoded as JSON
			// ( each property of the object represents a column of the CSV )
			format = 3;

			// If not fields supplied, use all properties
			if( !fields )
				fields = properties;
		}
	}


	// Create table and columns
	var result = new Table();
	for (var i = 0; i < fields.length; i++) {
		var fieldName = fields[i];
		var column = new List();
		result[i] = column;
		column.name = fieldName;
	};

	// Fill the table
	if( format == 1)
	{
		for (var i = 0; i < object.length; i++) {
			var row = object[i];
			for( var f=0; f<fields.length; f++ ){
				result[f].push( row[fields[f]]);
			}
		};
	}else{
		for( var f=0; f<fields.length; f++ ){
			var column = object[ fields[f] ];
			for (var i = 0; i < column.length; i++) {
				result[f].push( column[i] );
			}
		};
	}

	// Improve columns
	for (var i = 0; i < result.length; i++) {
		result[i] = result[i].getImproved()
	}

	// Improve table
	result = result.getImproved();

	// Return best possible
	return result;
}


/**
* Convert a Array of Constant-Length-Arrays into a Table
* @param {array} array of constant-length-arrays
*
* @param {List} list of field names to include (by default it will generate ["X1", "X2", "X3", ...] following R's behaviour.)
* @return {Table} resulting Table
* tags:decoder,javier
*/
TableConversions.ArrayToTable = function(array, fields){

	// This function can probably be merged with ObjectToTable. The only difference is that the elements on each row of the
	// original array cannot be accessed using row[fields[f]]. An additional Format option should be added for this particular
	// type of "table". I guess the automatic fields assignment is another difference.


	if(fields!){
		var fields = Array.apply(0, Array(array[0].length)).map(function (x, y) { return y + 1; });
		fields = fields.map(function (x) { return 'X' + x.toString(); });
	}

	// Create table and columns

	var result = new Table();
	for (var i = 0; i < fields.length; i++) {
		var fieldName = fields[i];
		var column = new List();
		result[i] = column;
		column.name = fieldName;
	}

	// Fill the table

	for ( var i = 0; i < array.length; i++ ) {
		var row = array[i];
		for( var f = 0; f < fields.length; f++ ){
			result[f].push( row[f] ); // The main difference with ObjectToTable is here
		}
	}

	// Improve columns
	for (var i = 0; i < result.length; i++) {
		result[i] = result[i].getImproved()
	}

	// Improve table
	result = result.getImproved();<commit_msg>Fixed minor ! problem<commit_after>function TableConversions(){};

/**
 * Convert an object (or more typically an Array of objects) into a Table
 * @param {Object} object or array of objects
 *
 * @param {List} list of field names to include (by default will take all from first element in array of objects)
 * @return {Table} resulting Table
 * tags:decoder,dani
 */
TableConversions.ObjectToTable = function(object, fields){
	// Formats:
	// 1: normal list of objects
	// 2: Object with single property, containing normal list of obejcts
	// 3: Object as CSV (each property represents a column)
	var format;

	// If it's an array, then it's format 1
	if( Array.isArray(object) ){
		format = 1;
		// If not field names supplied, get them from first element
		if( !fields )
		{
			fields = [];
			for( var p in object[0] ){
				fields.push( p );
			}
		}
	// Else (not array), it's an object
	}else{
		// Check how many properties the object has
		var properties = [];
		for( var p in object ){
			properties.push( p );
		}

		// If it has only one, and it's an array, it's foramt 2, so assume it's just a capsule
		// and extract the array as format 1
		if( properties.length == 1 && Array.isArray( object[properties[0]] ) )
		{
			format = 1;
			object = object[properties[0]];

			// If not field names supplied, get them from first element
			if( !fields )
			{
				fields = [];
				for( var p in object[0] ){
					fields.push( p );
				}
			}
		}else{
			// Finally, if the object has many properties, we assume it's a csv encoded as JSON
			// ( each property of the object represents a column of the CSV )
			format = 3;

			// If not fields supplied, use all properties
			if( !fields )
				fields = properties;
		}
	}


	// Create table and columns
	var result = new Table();
	for (var i = 0; i < fields.length; i++) {
		var fieldName = fields[i];
		var column = new List();
		result[i] = column;
		column.name = fieldName;
	};

	// Fill the table
	if( format == 1)
	{
		for (var i = 0; i < object.length; i++) {
			var row = object[i];
			for( var f=0; f<fields.length; f++ ){
				result[f].push( row[fields[f]]);
			}
		};
	}else{
		for( var f=0; f<fields.length; f++ ){
			var column = object[ fields[f] ];
			for (var i = 0; i < column.length; i++) {
				result[f].push( column[i] );
			}
		};
	}

	// Improve columns
	for (var i = 0; i < result.length; i++) {
		result[i] = result[i].getImproved()
	}

	// Improve table
	result = result.getImproved();

	// Return best possible
	return result;
}


/**
* Convert a Array of Constant-Length-Arrays into a Table
* @param {array} array of constant-length-arrays
*
* @param {List} list of field names to include (by default it will generate ["X1", "X2", "X3", ...] following R's behaviour.)
* @return {Table} resulting Table
* tags:decoder,javier
*/
TableConversions.ArrayToTable = function(array, fields){

	// This function can probably be merged with ObjectToTable. The only difference is that the elements on each row of the
	// original array cannot be accessed using row[fields[f]]. An additional Format option should be added for this particular
	// type of "table". I guess the automatic fields assignment is another difference.


	if( !fields ){
		var fields = Array.apply(0, Array(array[0].length)).map(function (x, y) { return y + 1; });
		fields = fields.map(function (x) { return 'X' + x.toString(); });
	}

	// Create table and columns

	var result = new Table();
	for (var i = 0; i < fields.length; i++) {
		var fieldName = fields[i];
		var column = new List();
		result[i] = column;
		column.name = fieldName;
	}

	// Fill the table

	for ( var i = 0; i < array.length; i++ ) {
		var row = array[i];
		for( var f = 0; f < fields.length; f++ ){
			result[f].push( row[f] ); // The main difference with ObjectToTable is here
		}
	}

	// Improve columns
	for (var i = 0; i < result.length; i++) {
		result[i] = result[i].getImproved()
	}

	// Improve table
	result = result.getImproved();
{'fraction_non_alphanumeric': 0.1381795195954488, 'fraction_numerical': 0.007838179519595449, 'mean_word_length': 3.011663286004057, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5755851', 'n_tokens_mistral': 2866, 'n_tokens_neox': 2537, 'n_words': 982}