Back to articles
Day 4 – Array Problem Solving Practice (JavaScript)

Day 4 – Array Problem Solving Practice (JavaScript)

via Dev.toThiru Sakthi

Today I practiced multiple array and loop-based problems to strengthen my fundamentals. πŸ’» Problems Covered Sum of array elements Find max & min in array Count even/odd numbers Reverse an array Remove duplicates Search a specific element Sliding window sum (basic idea) Subarray sum calculation Array rotation 🧠 Code Practice // 1. Sum of array let values = [ 1 , 2 , 3 , 4 , 5 ]; let result = 0 ; for ( let i = 0 ; i < values . length ; i ++ ){ result += values [ i ]; } console . log ( result ); // 2. Find max values = [ 1 , 2 , 3 , 4 ]; let max = values [ 0 ]; for ( let i = 0 ; i < values . length ; i ++ ){ if ( values [ i ] > max ){ max = values [ i ]; } } console . log ( max ); // 3. Find min values = [ 9 , 1 , 2 , 3 , 4 ]; let min = values [ 0 ]; for ( let i = 0 ; i < values . length ; i ++ ){ if ( values [ i ] < min ){ min = values [ i ]; } } console . log ( min ); // 4. Count even / odd values = [ 9 , 1 , 2 , 3 , 4 ]; let even = 0 ; let odd = 0 ; for ( let i = 0 ; i < values . length

Continue reading on Dev.to

Opens in a new tab

Read Full Article
2 views

Related Articles