-
Notifications
You must be signed in to change notification settings - Fork 22.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
116 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
d3.max = function(array, f) { | ||
var i = 0, | ||
var i = -1, | ||
n = array.length, | ||
a = array[0], | ||
a = -Infinity, | ||
b; | ||
if (arguments.length === 1) { | ||
while (++i < n) if (a < (b = array[i])) a = b; | ||
while (++i < n) if ((b = array[i]) != null && b > a) a = b; | ||
} else { | ||
a = f(a); | ||
while (++i < n) if (a < (b = f(array[i]))) a = b; | ||
while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b; | ||
} | ||
return a; | ||
}; |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
d3.min = function(array, f) { | ||
var i = 0, | ||
var i = -1, | ||
n = array.length, | ||
a = array[0], | ||
a = Infinity, | ||
b; | ||
if (arguments.length === 1) { | ||
while (++i < n) if (a > (b = array[i])) a = b; | ||
while (++i < n) if ((b = array[i]) != null && a > b) a = b; | ||
} else { | ||
a = f(array[0]); | ||
while (++i < n) if (a > (b = f(array[i]))) a = b; | ||
while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b; | ||
} | ||
return a; | ||
}; |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require("./../lib/env-js/envjs/node"); | ||
require("./../d3"); | ||
|
||
console.log("max:"); | ||
console.log(" " + d3.max([1, 2, 3, 4, 5])); | ||
console.log(""); | ||
|
||
console.log("max with accessor function:"); | ||
console.log(" " + d3.max([[1, 2, 3, 4, 5], [2, 4, 6, 8, 10]], function(d) { | ||
return d3.max(d); | ||
})); | ||
console.log(""); | ||
|
||
console.log("max index:"); | ||
console.log(" " + d3.max([1, 2, 3, 4, 5], function(d, i) { | ||
return i; | ||
})); | ||
console.log(""); | ||
|
||
console.log("max with first element NaN:"); | ||
console.log(" " + d3.max([NaN, 1, 2, 3, 4, 5])); | ||
console.log(""); | ||
|
||
console.log("max with last element NaN:"); | ||
console.log(" " + d3.max([1, 2, 3, 4, 5, NaN])); | ||
console.log(""); | ||
|
||
console.log("max with null and undefined elements:"); | ||
console.log(" " + d3.max([-5, null, -3, undefined, -10, NaN])); | ||
console.log(""); |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
max: | ||
5 | ||
|
||
max with accessor function: | ||
10 | ||
|
||
max index: | ||
4 | ||
|
||
max with first element NaN: | ||
5 | ||
|
||
max with last element NaN: | ||
5 | ||
|
||
max with null and undefined elements: | ||
-3 | ||
|
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require("./../lib/env-js/envjs/node"); | ||
require("./../d3"); | ||
|
||
console.log("min:"); | ||
console.log(" " + d3.min([1, 2, 3, 4, 5])); | ||
console.log(""); | ||
|
||
console.log("min with accessor function:"); | ||
console.log(" " + d3.min([[1, 2, 3, 4, 5], [2, 4, 6, 8, 10]], function(d) { | ||
return d3.max(d); | ||
})); | ||
console.log(""); | ||
|
||
console.log("min index:"); | ||
console.log(" " + d3.min([1, 2, 3, 4, 5], function(d, i) { | ||
return i; | ||
})); | ||
console.log(""); | ||
|
||
console.log("min with first element NaN:"); | ||
console.log(" " + d3.min([NaN, 1, 2, 3, 4, 5])); | ||
console.log(""); | ||
|
||
console.log("min with last element NaN:"); | ||
console.log(" " + d3.min([1, 2, 3, 4, 5, NaN])); | ||
console.log(""); | ||
|
||
console.log("min with null and undefined elements:"); | ||
console.log(" " + d3.min([10, null, 3, undefined, 5, NaN])); | ||
console.log(""); |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
min: | ||
1 | ||
|
||
min with accessor function: | ||
5 | ||
|
||
min index: | ||
0 | ||
|
||
min with first element NaN: | ||
1 | ||
|
||
min with last element NaN: | ||
1 | ||
|
||
min with null and undefined elements: | ||
3 | ||
|