Skip to content

Latest commit

 

History

History
31 lines (22 loc) · 762 Bytes

find-the-capitals.md

File metadata and controls

31 lines (22 loc) · 762 Bytes

Find the capitals 7 Kyu

LINK TO THE KATA - STRINGS ARRAYS FUNDAMENTALS

Description

Write a function that takes a single non-empty string of only lowercase and uppercase ascii letters (word) as its argument, and returns an ordered list containing the indices of all capital (uppercase) letters in the string.

Example (Input --> Output)

"CodEWaRs" --> [0,3,4,6]

Solution

const capitals = word => {
  const result = []

  for (let i = 0; i < word.length; i++) {
    if (word[i] === word[i].toUpperCase()) result.push(i)
  }

  return result
}