Skip to content

Instantly share code, notes, and snippets.

@shenqihui
Last active May 28, 2020 09:54
Show Gist options
  • Save shenqihui/f782dc77214ea7f9e78eb1ededc7209f to your computer and use it in GitHub Desktop.
Save shenqihui/f782dc77214ea7f9e78eb1ededc7209f to your computer and use it in GitHub Desktop.
每日一题

有数据

var area = [
{id:110000000000,pid: 0, name:"北京"},
{id:120000000000,pid: 0, name:"天津"},
{id:130000000000,pid: 0, name:"河北省"},
{id:140000000000,pid: 0, name:"山西省"},
{id:150000000000,pid: 0, name:"内蒙古自治区"},
{id:210000000000,pid: 0, name:"辽宁省"},
{id:220000000000,pid: 0, name:"吉林省"},
{id:230000000000,pid: 0, name:"黑龙江省"},
{id:310000000000,pid: 0, name:"上海"},
{id:320000000000,pid: 0, name:"江苏省"},
{id:330000000000,pid: 0, name:"浙江省"},
{id:340000000000,pid: 0, name:"安徽省"},
{id:350000000000,pid: 0, name:"福建省"},
{id:360000000000,pid: 0, name:"江西省"},
{id:370000000000,pid: 0, name:"山东省"},
{id:410000000000,pid: 0, name:"河南省"},
{id:420000000000,pid: 0, name:"湖北省"},
{id:430000000000,pid: 0, name:"湖南省"},
{id:440000000000,pid: 0, name:"广东省"},
{id:440100000000,pid: 440000000000, name:"广州市"},
{id:440103000000,pid: 440100000000, name:"荔湾区"},
{id:440104000000,pid: 440100000000, name:"越秀区"},
{id:440105000000,pid: 440100000000, name:"海珠区"},
{id:440106000000,pid: 440100000000, name:"天河区"},
{id:440111000000,pid: 440100000000, name:"白云区"},
{id:440112000000,pid: 440100000000, name:"黄埔区"},
{id:440113000000,pid: 440100000000, name:"番禺区"},
{id:440114000000,pid: 440100000000, name:"花都区"},
{id:440115000000,pid: 440100000000, name:"南沙区"},
{id:440117000000,pid: 440100000000, name:"从化区"},
{id:440118000000,pid: 440100000000, name:"增城区"},
{id:440200000000,pid: 440000000000, name:"韶关市"},
{id:440203000000,pid: 440200000000, name:"武江区"},
{id:440204000000,pid: 440200000000, name:"浈江区"},
{id:440205000000,pid: 440200000000, name:"曲江区"},
{id:440222000000,pid: 440200000000, name:"始兴县"},
{id:440224000000,pid: 440200000000, name:"仁化县"},
{id:440229000000,pid: 440200000000, name:"翁源县"},
{id:440232000000,pid: 440200000000, name:"乳源瑶族自治县"},
{id:440233000000,pid: 440200000000, name:"新丰县"},
{id:440281000000,pid: 440200000000, name:"乐昌市"},
{id:440282000000,pid: 440200000000, name:"南雄市"},
{id:440300000000,pid: 440000000000, name:"深圳市"},
{id:440303000000,pid: 440300000000, name:"罗湖区"},
{id:440304000000,pid: 440300000000, name:"福田区"},
{id:440305000000,pid: 440300000000, name:"南山区"},
{id:440306000000,pid: 440300000000, name:"宝安区"},
{id:440307000000,pid: 440300000000, name:"龙岗区"},
{id:440308000000,pid: 440300000000, name:"盐田区"},
{id:440309000000,pid: 440300000000, name:"龙华区"},
{id:440310000000,pid: 440300000000, name:"坪山区"},
{id:440400000000,pid: 440000000000, name:"珠海市"},
{id:440402000000,pid: 440400000000, name:"香洲区"},
{id:440403000000,pid: 440400000000, name:"斗门区"},
{id:440404000000,pid: 440400000000, name:"金湾区"},
{id:440500000000,pid: 440000000000, name:"汕头市"},
{id:440507000000,pid: 440500000000, name:"龙湖区"},
{id:440511000000,pid: 440500000000, name:"金平区"},
{id:440512000000,pid: 440500000000, name:"濠江区"},
{id:440513000000,pid: 440500000000, name:"潮阳区"},
{id:440514000000,pid: 440500000000, name:"潮南区"},
{id:440515000000,pid: 440500000000, name:"澄海区"},
{id:440523000000,pid: 440500000000, name:"南澳县"},
{id:440600000000,pid: 440000000000, name:"佛山市"},
{id:440604000000,pid: 440600000000, name:"禅城区"},
{id:440605000000,pid: 440600000000, name:"南海区"},
{id:440606000000,pid: 440600000000, name:"顺德区"},
{id:440607000000,pid: 440600000000, name:"三水区"},
{id:440608000000,pid: 440600000000, name:"高明区"},
{id:440700000000,pid: 440000000000, name:"江门市"},
{id:440703000000,pid: 440700000000, name:"蓬江区"},
{id:440704000000,pid: 440700000000, name:"江海区"},
{id:440705000000,pid: 440700000000, name:"新会区"},
{id:440781000000,pid: 440700000000, name:"台山市"},
{id:440783000000,pid: 440700000000, name:"开平市"},
{id:440784000000,pid: 440700000000, name:"鹤山市"},
{id:440785000000,pid: 440700000000, name:"恩平市"},
{id:440800000000,pid: 440000000000, name:"湛江市"},
{id:440802000000,pid: 440800000000, name:"赤坎区"},
{id:440803000000,pid: 440800000000, name:"霞山区"},
{id:440804000000,pid: 440800000000, name:"坡头区"},
{id:440811000000,pid: 440800000000, name:"麻章区"},
{id:440823000000,pid: 440800000000, name:"遂溪县"},
{id:440825000000,pid: 440800000000, name:"徐闻县"},
{id:440881000000,pid: 440800000000, name:"廉江市"},
{id:440882000000,pid: 440800000000, name:"雷州市"},
{id:440883000000,pid: 440800000000, name:"吴川市"},
{id:440900000000,pid: 440000000000, name:"茂名市"},
{id:440902000000,pid: 440900000000, name:"茂南区"},
{id:440904000000,pid: 440900000000, name:"电白区"},
{id:440981000000,pid: 440900000000, name:"高州市"},
{id:440982000000,pid: 440900000000, name:"化州市"},
{id:440983000000,pid: 440900000000, name:"信宜市"},
{id:441200000000,pid: 440000000000, name:"肇庆市"},
{id:441202000000,pid: 441200000000, name:"端州区"},
{id:441203000000,pid: 441200000000, name:"鼎湖区"},
{id:441204000000,pid: 441200000000, name:"高要区"},
{id:441223000000,pid: 441200000000, name:"广宁县"},
{id:441224000000,pid: 441200000000, name:"怀集县"},
{id:441225000000,pid: 441200000000, name:"封开县"},
{id:441226000000,pid: 441200000000, name:"德庆县"},
{id:441284000000,pid: 441200000000, name:"四会市"},
{id:441300000000,pid: 440000000000, name:"惠州市"},
{id:441302000000,pid: 441300000000, name:"惠城区"},
{id:441303000000,pid: 441300000000, name:"惠阳区"},
{id:441322000000,pid: 441300000000, name:"博罗县"},
{id:441323000000,pid: 441300000000, name:"惠东县"},
{id:441324000000,pid: 441300000000, name:"龙门县"},
{id:441400000000,pid: 440000000000, name:"梅州市"},
{id:441402000000,pid: 441400000000, name:"梅江区"},
{id:441403000000,pid: 441400000000, name:"梅县区"},
{id:441422000000,pid: 441400000000, name:"大埔县"},
{id:441423000000,pid: 441400000000, name:"丰顺县"},
{id:441424000000,pid: 441400000000, name:"五华县"},
{id:441426000000,pid: 441400000000, name:"平远县"},
{id:441427000000,pid: 441400000000, name:"蕉岭县"},
{id:441481000000,pid: 441400000000, name:"兴宁市"},
{id:441500000000,pid: 440000000000, name:"汕尾市"},
{id:441502000000,pid: 441500000000, name:"城区"},
{id:441521000000,pid: 441500000000, name:"海丰县"},
{id:441523000000,pid: 441500000000, name:"陆河县"},
{id:441581000000,pid: 441500000000, name:"陆丰市"},
{id:441600000000,pid: 440000000000, name:"河源市"},
{id:441602000000,pid: 441600000000, name:"源城区"},
{id:441621000000,pid: 441600000000, name:"紫金县"},
{id:441622000000,pid: 441600000000, name:"龙川县"},
{id:441623000000,pid: 441600000000, name:"连平县"},
{id:441624000000,pid: 441600000000, name:"和平县"},
{id:441625000000,pid: 441600000000, name:"东源县"},
{id:441700000000,pid: 440000000000, name:"阳江市"},
{id:441702000000,pid: 441700000000, name:"江城区"},
{id:441704000000,pid: 441700000000, name:"阳东区"},
{id:441721000000,pid: 441700000000, name:"阳西县"},
{id:441781000000,pid: 441700000000, name:"阳春市"},
{id:441800000000,pid: 440000000000, name:"清远市"},
{id:441802000000,pid: 441800000000, name:"清城区"},
{id:441803000000,pid: 441800000000, name:"清新区"},
{id:441821000000,pid: 441800000000, name:"佛冈县"},
{id:441823000000,pid: 441800000000, name:"阳山县"},
{id:441825000000,pid: 441800000000, name:"连山壮族瑶族自治县"},
{id:441826000000,pid: 441800000000, name:"连南瑶族自治县"},
{id:441881000000,pid: 441800000000, name:"英德市"},
{id:441882000000,pid: 441800000000, name:"连州市"},
{id:441900000000,pid: 440000000000, name:"东莞市"},
{id:442000000000,pid: 440000000000, name:"中山市"},
{id:445100000000,pid: 440000000000, name:"潮州市"},
{id:445102000000,pid: 445100000000, name:"湘桥区"},
{id:445103000000,pid: 445100000000, name:"潮安区"},
{id:445122000000,pid: 445100000000, name:"饶平县"},
{id:445200000000,pid: 440000000000, name:"揭阳市"},
{id:445202000000,pid: 445200000000, name:"榕城区"},
{id:445203000000,pid: 445200000000, name:"揭东区"},
{id:445222000000,pid: 445200000000, name:"揭西县"},
{id:445224000000,pid: 445200000000, name:"惠来县"},
{id:445281000000,pid: 445200000000, name:"普宁市"},
{id:445300000000,pid: 440000000000, name:"云浮市"},
{id:445302000000,pid: 445300000000, name:"云城区"},
{id:445303000000,pid: 445300000000, name:"云安区"},
{id:445321000000,pid: 445300000000, name:"新兴县"},
{id:445322000000,pid: 445300000000, name:"郁南县"},
{id:445381000000,pid: 445300000000, name:"罗定市"},
{id:450000000000,pid: 0, name:"广西壮族自治区"},
{id:460000000000,pid: 0, name:"海南省"},
{id:500000000000,pid: 0, name:"重庆"},
{id:510000000000,pid: 0, name:"四川省"},
{id:520000000000,pid: 0, name:"贵州省"},
{id:530000000000,pid: 0, name:"云南省"},
{id:540000000000,pid: 0, name:"西藏自治区"},
{id:610000000000,pid: 0, name:"陕西省"},
{id:620000000000,pid: 0, name:"甘肃省"},
{id:630000000000,pid: 0, name:"青海省"},
{id:640000000000,pid: 0, name:"宁夏回族自治区"},
{id:650000000000,pid: 0, name:"新疆维吾尔自治区"}
];

其中 pid 为父级节点的id,pid 为0 时候为树根,创建一棵树

function areaTree(arr) {
  var tree;
  // do something
  
  return tree;
}

用原型链方式写一个 Animal 类及其两个不同实例。

条件一:定义属性方法 say ,实现 animalA.say !== animalB.say 及 animalA.proto.say === animalB.proto.say (注意审题,非方法的调用,是方法指向)
条件二:实现 gender 方法,标记该实例的性别。
条件三:实现 Animal.male() ,返回所有已创建且为雄性的实例。

以下是部分代码:

function Animal(props) {
  this.name = props.name;
}

var animalA = new Animal({ name: '小白鼠A' });
var animalB = new Animal({ name: '小白鼠B' });
animalA.say !== animalB.say // true
animalA.__proto__.say === animalB.__proto__.say // true
animalA.gender('male');
animalB.gender('female');
Animal.gender('male') // 返回包含 animalA 的数组。

0527早上交答案。

写一个稳定的排序。进行人员的年龄+成绩的稳定排序。

年龄小的排前面,成绩大的优先,相等的话按照原来传入的顺序。

[
  {
    index: 1,
    age: 9,
    score: 10,
  },
  {
    index: 2,
    age: 9,
    score: 10,
  },
  {
    index: 3,
    age: 8,
    score: 10,
  },
  {
    index: 4,
    age: 8,
    score: 7,
  },
  {
    index: 4,
    age: 6,
    score: 11,
  },
  {
    index: 4,
    age: 6,
    score: 5,
  },
]

上题的变形,排序条件增加使用某些优先条件。这个时候不考虑排序是否稳定。

如年龄范围在 [7,8] ,就排在最前面,适龄儿童优先录取,其他不是7、8岁的,按照分数录取,相同分数优先录取年龄小的。
还有一个神童录取规则,分数大于20的,不受到年龄限制,不同分数会忽略年龄的因素进行排序。

最终规则:

  • 分数大于等于20分的,排在数组前面,这是最优排序规则
  • 年龄段优先规则,如果是某个年龄段,排在数组前面,这是第二优排序规则
  • 相同分数,年龄优先,不同分数分数优先。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment