QA

let s = "This is C programming text";
let t = "This is a text for C programming";
   
//时间复杂度:O(n^2)
//空间复杂度:O(1)
function f1(str1,str2,r){
    let arr1 = str1.split(" "),
    arr2 = str2.split(" "),
    res = [];
    if(r>Math.min(arr1.length,arr2.length)||r<1)return null;
    //思路:1找出公共数组
    for(let i=0;i {
        if(!res[item.length]){
            res[item.length] = item
        }
    });

    //3剩下的排序
    res.sort((a,b)=>a.length

//穷举法
//时间复杂度:O(n^2)
//空间复杂度:O(1)
function fn(num){
    let res = [];
    //找到符合条件的首个数字i和项数n
    for(let i = 1;inum){
                break
            }
        }
    };
    //输出
    if(res.length>0){
        let output = "";
        res.forEach(item=>{
            for(var i = 0;i<=item[1];i++){
                output+=item[0]+++' ';
            }
            output+="\n";
        })
        return output;
    }else{
        return "NONE";
    }
    }

1.链接:https://yzbaoo.github.io/resume/
项目地址:https://github.com/yzbaoo/resume
2.链接:https://yzbaoo.github.io/Trav...
项目地址:https://github.com/yzbaoo/Tra...

红色:去过
绿色:计划去
功能点1:右键map添加计划
功能点2:右键未完成计划可更改完成状态和删除计划
功能点3:已去过的省份不可再次添加计划
功能点4:鼠标hover显示时间和备注
思路:
1.mockdata:
        var dataSource = [
            {
                province:"黑龙江省",
                point:{lng: 129.466081, lat: 44.625683},
                desc:"my hometown",
                time:"2018-7-5",
                type:0,//0:去过,1:计划去
            },{
                province:"辽宁省",
                point:{lng: 124.535605, lat: 41.979285},
                desc:"2015年4月",
                time:"2018-7-5",
                type:0,//0:去过,1:计划去
            },{
                province:"北京市",
                point:{lng: 116.146438, lat: 39.77318},
                desc:"Dream start!",
                time:"2018-7-5",
                type:0,//0:去过,1:计划去
            },{
                province:"四川省",
                point:{lng: 107.131762, lat: 30.083521},
                desc:"计划今年十一去嗨!!",
                time:"2018-7-5",
                type:1,//0:去过,1:计划去
            }
        ]; 
    2.编写renderMark方法,实现data驱动ui变化 
//渲染函数    
function renderMark(){
    map.clearOverlays();
    dataSource.forEach((d,i)=>{
        //渲染mark
        var marker = new BMap.Marker(d.point,{
            icon: new BMap.Symbol(BMap_Symbol_SHAPE_STAR, {
                scale: 2,
                fillColor: d.type===0 ? "red" : "#51C332",
                fillOpacity: 0.8,
                strokeColor:"#fff",
            })
        }); 
        map.addOverlay(marker);             
        marker.setAnimation(d.type===0 ? BMAP_ANIMATION_DROP : BMAP_ANIMATION_BOUNCE); //动画
        //渲染title
        var title = "时 间: " + d.time + "\n\r" + "描 述: " + d.desc;
        marker.setTitle(d.type===0 ? "已占领"+ "\n\r" +title:"计划"+ "\n\r" +title);
        //为type=1的mark绑定右键编辑事件
        if(d.type===1){
            var menu = new BMap.ContextMenu();
            var txtMenuItem = [
                {
                    text:'标记完成',
                    callback:function(i){
                        dataSource[i].type=0;
                        renderMark()
                    }
                },{
                    text:'删除计划',
                    callback:function(i){
                        dataSource.splice(i,1);
                        renderMark()
                    }
                }

            ];
            txtMenuItem.forEach(d2=>{
                menu.addItem(new BMap.MenuItem(d2.text,d2.callback.bind(this,i),100));
            })
            marker.addContextMenu(menu);
        }
    })
}

你可能感兴趣的:(javascript)