https://leetcode.com/problems/count-hills-and-valleys-in-an-array



Runtime: 108 ms, faster than 100.00% of TypeScript online submissions for Count Hills and Valleys in an Array.

Memory Usage: 45.6 MB, less than 100.00% of TypeScript online submissions for Count Hills and Valleys in an Array.



```typescript
function countHillValley(nums: number[]): number {
    //8:06
    let new_nums = []
    for (const [index, value] of nums.entries()) {
        if (new_nums.length == 0) {
            new_nums.push(value)
        } else {
            if (value != new_nums[new_nums.length - 1]) {
                new_nums.push(value)
            }
        }
    }
    
    let counting = 0
    for (const [index, value] of new_nums.entries()) {
        if ((index != 0) && (index != new_nums.length)) {
            let previous = new_nums[index-1]
            let next = new_nums[index+1]
            if ((value > previous) && (value > next)) {
                counting += 1
            }
            if ((value < previous) && (value < next)) {
                counting += 1
            }
        } 
    }
    
    return counting;
    //8:10
};
```
