We are going to write a function called
findEvenIndex that accepts an array,
arr, as an argument.
You are given an array of integers. The purpose of the function is to take the array and return the index where the sum of the integers to the left of the index is equal to the sum of integers to the right of the index. If there is no such thing or if the array is empty, return
[1,2,3,4,3,2,1] // output: 3 [1,100,50,-51,1,1] // output: 1
If we look at the first example, the fourth number (index 3) is where the sum of the left side of the index equals the sum of the right side of the index.
Left side of index 3:
1 + 2 + 3 = 6
Right side of index 3:
3 + 2 + 1 = 6
If you look at the second example. It’s the same thing:
To the left of index 1:
To the right of index 1:
50 + -51 + 1 + 1 = 1
Who else loves to write side-effects-free functions? I think we, as programmers, all do. Today, in this story, I will walk you through the basic principles of functional programming that will make your coding life easier.
I previously wrote about some common coding algorithms that you’ll run into on your job search. The article was received fairly well so I thought I’d do a couple more to help in your journey to becoming more familiar with algorithms.
This tricky Kadane’s Algorithm with a deceptively simple solution is a great introduction to more optimal problem-solving practices. Continue ...
This article will introduce the concepts and topics common to all programming languages, that beginners and experts must know!