Skip to content

Instantly share code, notes, and snippets.

@colin-han
Last active April 1, 2019 07:48
Show Gist options
  • Save colin-han/a251fcf2ae9e50e473493e3a798fb6a9 to your computer and use it in GitHub Desktop.
Save colin-han/a251fcf2ae9e50e473493e3a798fb6a9 to your computer and use it in GitHub Desktop.
Promise-exam

背景

在线人名生成服务

我们可以通过向 (https://www.toolnb.com/Tools/Api/mzsc.html) 发送POST请求获得一组人 名,请求数据类似于:create_number=50&number=3&username=赵

其中:create_number为创建人名数量,number为人名字数,username为姓。

在线汉字转拼音服务

通过向 (http://api.avatardata.cn/XinHuaZiDian/LookUp?key=xxxxxxxxxxxxxxx&content=赵) 发送GET请 求,可以查询汉字”赵“对应的拼音信息。

其中查询中的key是访问api需要的appKey,请自行到阿凡达数据注册申请, content为需要查询的汉字。

问题

现在要求你实现一段NodeJS模块,要求该模块使用node-fetch 包进行网络请求。利用上面的两个在线服务实现如下功能:

  1. 分别使用['赵','钱','孙','李']四个姓向人名生成服务请求100个3字姓名,将返回的结果保存到一个日志文件(log.txt)中,
  2. 找到返回姓名的名字中出现次数最多的汉子。
  3. 通过汉字转拼音服务查询该汉字对应的带声调拼音(返回结果中的"duyin"字段的值),输出拼音到控制台中。

请尽可能注意代码书写规范性和功能可扩展性。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment