From 6918366fcb531be629cdb4952e63a6543b4573f2 Mon Sep 17 00:00:00 2001 From: Kristyn Bryan Date: Fri, 27 May 2016 15:00:38 -0400 Subject: [PATCH] Update Solution.js --- unit_01/w03d02/morning_exercise/Solution.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/unit_01/w03d02/morning_exercise/Solution.js b/unit_01/w03d02/morning_exercise/Solution.js index 409146a..3a21f7b 100644 --- a/unit_01/w03d02/morning_exercise/Solution.js +++ b/unit_01/w03d02/morning_exercise/Solution.js @@ -1,5 +1,6 @@ -// least efficient -var diff = function(arr){ +// least efficient - WHY? Could you see a situation where this could be inefficient? +// in this one, you're creating two loops. The first loop holds on to one index number (position 0) and the second loop compares it to every other number in the loop (index 0, 1, 2, etc.) +var difference = function(arr){ var biggest = 0 for (var i = 0; i < arr.length; i++) { for (var j = 0; j < arr.length; j++) { @@ -11,7 +12,7 @@ var diff = function(arr){ return biggest } -console.log(diff([1,4, 6, 2, 9])) +console.log(difference([1, 4, 6, 2, 9])) // more efficient