How to Print Alternate Elements of an Array in JavaScript (DSA)
Source: Dev.to
โ ๏ธ Collection Error: Content refinement error: Error: 429 429 Too Many Requests: you (bkperio) have reached your weekly usage limit, upgrade for higher limits: https://ollama.com/upgrade
๐งฉ Problem: Alternate Elements of an Array
Given an array arr[], your task is to print every alternate element of the array starting from the first element. In other words, print elements at index 0, 2, 4, โฆ and skip the rest. An array of integers arr[] Print the alternate elements of the array (starting from index 0) Example 1: Input: arr[] = [10, 20, 30, 40, 50] Output: 10 30 50
Explanation: Example 2: Input: arr[] = [-5, 1, 4, 2, 12] Output: -5 4 12
1 โค arr.length โค 10^5 -10^9 โค arr[i] โค 10^9