Created
June 8, 2010 17:46
-
-
Save sidonath/430390 to your computer and use it in GitHub Desktop.
Revisions
-
sidonath revised this gist
Jun 8, 2010 . 1 changed file with 13 additions and 4 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 @@ -1,10 +1,19 @@ // approach one: simply assign function to prototype // it works, but you still need to use "apply" to make the method // work as needed function smallest1(array){ Array.prototype.min = Math.min; return array.min.apply(array, array); } // approach two: use apply in the function assigned to Array's prototype function smallest2(array){ Array.prototype.min = function () { return Math.min.apply(Math, this); }; return array.min(); } function largest(array){ return Math.max.apply( Math, array ); } assert(smallest1([0, 1, 2, 3]) == 0, "Locate the smallest value."); assert(smallest2([0, 1, 2, 3]) == 0, "Locate the smallest value."); assert(largest([0, 1, 2, 3]) == 3, "Locate the largest value."); -
jjb revised this gist
Jun 7, 2010 . 1 changed file with 1 addition and 1 deletion.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 @@ -1,7 +1,7 @@ Array.prototype.min = Math.min; function smallest(array){ return array.min(); } function largest(array){ return Math.max.apply( Math, array ); -
jjb revised this gist
Jun 7, 2010 . 1 changed file with 3 additions and 1 deletion.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 @@ -1,5 +1,7 @@ Array.prototype.min = Math.min; function smallest(array){ return array.min; } function largest(array){ return Math.max.apply( Math, array ); -
jjb created this gist
Jun 7, 2010 .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,8 @@ function smallest(array){ return Math.min.apply( Math, array ); } function largest(array){ return Math.max.apply( Math, array ); } assert(smallest([0, 1, 2, 3]) == 0, "Locate the smallest value."); assert(largest([0, 1, 2, 3]) == 3, "Locate the largest value.");