efficient solution | 1 line solution using reducer | filter
IntuitionThis solution counts the number of people who are seniors (older than 60 years) by extracting the age from each person's details string.Approach
Initia
# Intuition
This solution counts the number of people who are seniors (older than 60 years) by extracting the age from each person's details string.

# Approach

- Initialize a counter to track seniors
- Look at each person's details string
- Extract the age using ```slice(11, 13)``` which gets characters at positions 11-12
- Convert the extracted age to a number using ```parseInt()```
- Check if the age is greater than 60
- Increment the counter if the person is a senior
- Return the final count

# Complexity

- Time complexity: O(n)
    - We process each person's details exactly once
    - String slicing and parsing are constant time operations
- Space complexity: O(1)
    - We only use a single counter variable regardless of input size



# Code
```javascript []
/**
 * @param {string[]} details
 * @return {number}
 */
var countSeniors = function (details) {
    let count = 0;
    for (let detail of details) {
        if (parseInt(detail.slice(11, 13)) > 60) {
            count++;
        }
    }
    return count;
};
```

# concise alternative version using reduce:
```js
var countSeniors = function(details) {
    return details.reduce((count, detail) => 
        count + (parseInt(detail.slice(11, 13)) > 60 ? 1 : 0), 0);
};
```
# Or using filter:
```js
var countSeniors = function(details) {
    return details.filter(detail => parseInt(detail.slice(11, 13)) > 60).length;
};
```


['JavaScript']