zoukankan      html  css  js  c++  java
  • 用字母表中的位置替换每个字母。

    你需要给定一个字符串,用字母表中的位置替换每个字母。如果文本中的任何内容不是字母,请忽略它并不返回。

     1 function alphabetPosition(text) {
     2  let list = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
     3  text = text.toLowerCase().replace(/[W_]/g,'');
     4 console.log(text, 'b')
     5  let data = text.split('');
     6 console.log(data)
     7  let arr = [];
     8  data.forEach(function(ele) {
     9   for (let i = 0; i < list.length; i++) {
    10    if (ele == list[i]) {
    11     arr.push(i+1);
    12    }
    13   }
    14  })
    15   
    16  console.log(arr, 'a')
    17   
    18  return arr.join(' ');
    19 }
    20 alphabetPosition("The narwhal bacons at midnight")
  • 相关阅读:
    查看虚拟机里的Centos7的IP
    display:none visibility:hidden opacity:0区别
    UVA
    Gym
    Gym
    UVALive
    面试题1
    vuex的5个属性值
    vue中的.sync语法糖
    绝对定位实现垂直居中的优缺点
  • 原文地址:https://www.cnblogs.com/mxyr/p/9238277.html
Copyright © 2011-2022 走看看