diff --git a/lib/cartodb/api/overviews_metadata_api.js b/lib/cartodb/api/overviews_metadata_api.js index 4e6109c1..81ab1a1c 100644 --- a/lib/cartodb/api/overviews_metadata_api.js +++ b/lib/cartodb/api/overviews_metadata_api.js @@ -31,18 +31,17 @@ OverviewsMetadataApi.prototype.getOverviewsMetadata = function (username, sql, c callback(err); return; } - var metadata = {}; - rows.forEach(function(row) { + var metadata = rows.reduce(function(metadata, row){ var table = row.base_table; var schema = row._cdb_schema_name; var table_metadata = metadata[table]; if ( !table_metadata ) { - table_metadata = metadata[table] = {}; + table_metadata = metadata[table] = {}; } table_metadata[row.z] = { table: row.overview_table }; table_metadata.schema = schema; - }); + return metadata; + }, {}); return callback(null, metadata); }); - };