5 Star 50 Fork 0

Gitee Community / 码力传递:晒代码赢奖品

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
码力检测第三关.md 949 Bytes
一键复制 编辑 原始数据 按行查看 历史
g8up 提交于 2020-05-28 01:57 . Gitee 生日快乐!

Gitee 7 周年-码力检测第三关

书信

/** 转换为平仄,映射 0、1 */
const parseTone = (tone) => {
  return [3, 4].includes(tone)  ? 1 : 0;
};

const decode = (data) => {
  return data.map(bins => {
    return parseInt(bins.join(''), 2)
  });
};

const toChar = code => String.fromCharCode(code);

/** 按声调标注(轻声发音按单字原音) */
const tonesGroup = [
  [2, 4, 3, 2, 2, 1, 4, 1],
  [2, 4, 4, 4, 2, 4, 2, 4],
  [1, 4, 4, 1, 2, 4, 4, 4],
  [2, 4, 4, 4, 2, 1, 2, 2],
  [1, 4, 4, 2, 4, 4, 1, 2],
  [2, 4, 4, 1, 2, 1, 2, 3],
  [2, 3, 3, 2, 3, 4, 3, 2],
  [1, 4, 4, 1, 1, 4, 1, 4],
  [2, 4, 4, 4, 1, 4, 2, 1]
];

const binary = tonesGroup.map((tones) => {
  return tones.map(parseTone);
});

const answer = decode(binary).map(toChar).join('');

// console.log( 'binary:\n', binary );
console.log(answer);
1
https://gitee.com/gitee-community/gitee-7th-event-3.git
git@gitee.com:gitee-community/gitee-7th-event-3.git
gitee-community
gitee-7th-event-3
码力传递:晒代码赢奖品
master

搜索帮助