From 7050a32a386bcd538e160cdd7010bc76eee9ce9c Mon Sep 17 00:00:00 2001 From: Victor Widell Date: Mon, 15 Aug 2016 15:59:56 +0200 Subject: [PATCH] Rewrote for loop to functional find. --- ComposableSqlFromClause.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/ComposableSqlFromClause.js b/ComposableSqlFromClause.js index ca9afaa..4703c0f 100644 --- a/ComposableSqlFromClause.js +++ b/ComposableSqlFromClause.js @@ -74,18 +74,17 @@ function ComposableSqlFromClause (tables) { // If there is one, join to the first column that // has a foreign key to the table in this join. - // TODO: Rewrite with .find(). - for (var i = 0; i < earlierColumnsWithForeignKey.length; i++) { - var column = earlierColumnsWithForeignKey[i]; - - if (column.foreignKey.table == join.table) { + var column = earlierColumnsWithForeignKey + .find(function (column) { + return column.foreignKey.table == join.table; + }); + if (column) { - join.onExpression = new ComposableSqlEq( - join.table.columns[column.foreignKey.name], - column - ); - return; - } + join.onExpression = new ComposableSqlEq( + join.table.columns[column.foreignKey.name], + column + ); + return; } // Check if any of the columns in the table of this