背景:最近一朋友面试,二面机试题,题目大意是:
从百度天气的一个api取得天气数据,前端展示天气数据,穿衣指数,点击温度栏进行一个升温降温排序,以及不排序
接口地址:http://api.map.baidu.com/telematics/v3/weather?location=深圳&output=json&ak=lsTdWpHKKx2j4m1LhfDDXUgW
看着确实没什么难度,但是最后涉及排序的时候还是有一点值得思考的.
首先我们看看从百度拿到了什么数据
var data=
[
{
date: "周一 03月02日 (实时:9℃)",
dayPictureUrl: "http://api.map.baidu.com/images/weather/day/yin.png",
nightPictureUrl:
"http://api.map.baidu.com/images/weather/night/zhongyu.png",
weather: "阴转中雨",
wind: "西北风微风",
temperature: "11 ~ 8℃",
des: "建议着厚外套加毛衣等服装。年老体弱者宜着大衣、呢外套加羊毛衫。"
},
{
date: "周二",
dayPictureUrl: "http://api.map.baidu.com/images/weather/day/zhongyu.png",
nightPictureUrl:
"http://api.map.baidu.com/images/weather/night/xiaoyu.png",
weather: "中雨转小雨",