function getMin(list) { let ret = list.reduce((prev, curr) => { if (curr <= 0) return prev; return (prev <= 0) ? curr : Math.min(curr, prev); }, -1); return ret > 0 ? ret : 0; }
- function getMin(list) {
- let ret = list.reduce((prev, curr) => {
if (curr >= 1) {if (prev <= 0) {return curr;}else {return Math.min(curr, prev);}}return prev;- if (curr <= 0) return prev;
- return (prev <= 0) ? curr : Math.min(curr, prev);
- }, -1);
return ret >= 1 ? ret : 0;- return ret > 0 ? ret : 0;
- }
describe("Solution", function(){ it("test1", function(){ var list = [0, 1, 1, 3]; Test.assertEquals(getMin(list), 1, "test fails"); }); it("test2", function(){ var list = [7, 2, null, 3, 0, 10]; Test.assertEquals(getMin(list), 2, "test fails"); }); it("test3", function(){ var list = [null, -2]; Test.assertEquals(getMin(list), 0, "test fails"); }); it("test4", function(){ var list = [Number.MAX_VALUE]; Test.assertEquals(getMin(list), Number.MAX_VALUE, "test fails"); }); it("test5", function(){ var list = [0.5,7, 2, null, 3, 0, 10]; Test.assertEquals(getMin(list), 0.5, "test fails"); }); });
- describe("Solution", function(){
- it("test1", function(){
- var list = [0, 1, 1, 3];
- Test.assertEquals(getMin(list), 1, "test fails");
- });
- it("test2", function(){
- var list = [7, 2, null, 3, 0, 10];
- Test.assertEquals(getMin(list), 2, "test fails");
- });
- it("test3", function(){
- var list = [null, -2];
- Test.assertEquals(getMin(list), 0, "test fails");
- });
- it("test4", function(){
- var list = [Number.MAX_VALUE];
- Test.assertEquals(getMin(list), Number.MAX_VALUE, "test fails");
- });
- it("test5", function(){
- var list = [0.5,7, 2, null, 3, 0, 10];
- Test.assertEquals(getMin(list), 0.5, "test fails");
- });
- });