Last active
January 25, 2017 18:47
-
-
Save james-prado/4fd222d65f93aa6fc62c452942c3b5b7 to your computer and use it in GitHub Desktop.
Revisions
-
james-prado revised this gist
Jan 25, 2017 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,8 +9,7 @@ function quickSort(numbers, target, partial) { // check if the sum partial equals the target if (sum === target) { console.log("%s=%s", partial.join("+"), target + ', Sum: ' + sum + ', Target: ' + target + ', Partial: ' + partial + ', Remaining: ' + numbers); return; } else if (sum > target) { return // if we're past the target, there is no reason to continue -
james-prado revised this gist
Jan 25, 2017 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,11 +10,10 @@ function quickSort(numbers, target, partial) { // check if the sum partial equals the target if (sum === target) { console.log("%s=%s", partial.join("+"), target); console.log('Sum: ' + sum + ', Target: ' + target + ', Partial: ' + partial); return; } else if (sum > target) { return // if we're past the target, there is no reason to continue } for (var i = 0; i < numbers.length; i++) { @@ -24,4 +23,6 @@ function quickSort(numbers, target, partial) { } } // Examples quickSort([100, 50, 20, 10, 5, 1], 176); quickSort([3, 9, 8, 4, 5, 7, 10], 15); -
james-prado revised this gist
Jan 25, 2017 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,14 +7,14 @@ function quickSort(numbers, target, partial) { return a + b; }, 0); // check if the sum partial equals the target if (sum === target) { console.log("%s=%s", partial.join("+"), target); return; } else if (sum > target) { return // if we're past the target, there is no reason to continue } else { console.log('Sum: ' + sum + ', Target: ' + target + ', Partial: ' + partial); } for (var i = 0; i < numbers.length; i++) { -
james-prado created this gist
Jan 25, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ function quickSort(numbers, target, partial) { var sum, remaining; var partial = partial || []; // sum partial sum = partial.reduce(function (a, b) { return a + b; }, 0); // check if the partial sum is equals to target if (sum === target) { console.log("%s=%s", partial.join("+"), target); return; } else if (sum > target) { return // if we reach the number why bother to continue } else { console.log('Sum: ' + sum + ', Target: ' + target); } for (var i = 0; i < numbers.length; i++) { number = numbers[i]; remaining = numbers.slice(i + 1); quickSort(remaining, target, partial.concat([number])); } } quickSort([100, 50, 20, 10, 5, 1], 176);