Skip to content

Instantly share code, notes, and snippets.

@rodpoblete
Created December 1, 2017 02:58
Show Gist options
  • Save rodpoblete/9088d8b5752116fbab69fa8f8f8d9684 to your computer and use it in GitHub Desktop.
Save rodpoblete/9088d8b5752116fbab69fa8f8f8d9684 to your computer and use it in GitHub Desktop.
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.
// 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");
@cristofer-dev
Copy link

const capital = function(word) {
  const arr = word.split("");
  var arr2 = [];
  const arrOrdened = arr.filter(function(e, i, a) {
    if (e === e.toUpperCase()) {
      arr2.push(i)
    }
  });
  console.log(arr2)
};

capital("CodEWaRs");

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