cannot read property of undefined(入门级qwq自学小白求教

sinat_36203251 2016-09-21 08:51:58
这是一个学生网页开发比赛的报名测试qwq所以不是完整的
具体来说就是完成5个函数,然后它会随机输入这样格式的timeseries:
[
{
"date": "2016-05-04",
"price": 1.234
},
...
]
Time series might not be in chronological order.
Each function should return a single value.


其中有一个函数是找出时间最前的然后return相应的price,然后它一直报错cannot read property 'price' of undefined……我这两天才开始学,一边试一边写但是这个怎么都解决不了_(:з ∠)_百度错误原因也根本不明白
求教啊啊啊qwqqqqqq

我写的代码是这样子↓

function first(timeseries) {
// ↑↑函数名称是题目本来就有的
var count = 0;
var mintime = 99999999,mini;
var date = new Array();
if(timeseries === null || timeseries === undefined){
return;
}


for(var j = 0;j < timeseries.length;j ++){
//document.write("j:" + j + " ");
count = 0;
for(var x in timeseries[j]){
count = count + 1;
//document.write("ct:" + count + " ");
}
if(timeseries[j] === undefined || timeseries[j] === null){
return;
}
if(count != 2){
if(timeseries[j].date === undefined || timeseries[j].date === null){
throw"date is missing";
}else{
return undefined;
}

}
}



for(var k = 0;k < timeseries.length;k ++){
if(checkdate(timeseries[k]) == 1 && checkprice(timeseries[k]) == 1){
//document.write(" k:" + k + " ");
date[k] = seriestodate(timeseries[k]);
//document.write(" date[k]:" + date[k] + " ");
if(cprdate(mintime,date[k]) === 1){
mini = k;
mintime = date[k];
//document.write(" mini:" + mini + " mintime:" + mintime);
}
}else{
throw"date is missing";
}
}


return timeseries[mini].price;



}


求教qwqqqqqq
谢谢!!!
...全文
663 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
天际的海浪 2016-09-21
  • 打赏
  • 举报
回复
输出下mini看是否正确

87,904

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧