Update Solution.js

master
Kristyn Bryan 10 years ago
parent 4056cd8fd6
commit 6918366fcb

@ -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

Loading…
Cancel
Save