javascript 编写一个以单个字符串(单词)作为参数的函数。该函数必须返回包含所有capit索引的有序列表

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 编写一个以单个字符串(单词)作为参数的函数。该函数必须返回包含所有capit索引的有序列表相关的知识,希望对你有一定的参考价值。

// Instructions

// Write a function that takes a single string (word) as argument. The function must return an ordered list containing the indexes of all capital letters in the string.

// Test.assertSimilar( capitals('CodEWaRs'), [0,3,4,6] );

const capital = function(word) {
  const arr = word.split("");
  const arrOrdened = arr.map(function(e, i, a) {
    if (e === e.toUpperCase()) {
       return i;
    }
  });
  console.log(arrOrdened);
};

capital("CodEWaRs");

以上是关于javascript 编写一个以单个字符串(单词)作为参数的函数。该函数必须返回包含所有capit索引的有序列表的主要内容,如果未能解决你的问题,请参考以下文章