Im working on a problem in javascript where I am supposed to write a function that takes in an array of integers, and a string that will be either 'even' or 'odd'. The function will count how many times 4 even or 4 odd numbers show up in a row.
For example:
quadruples([3,2,2,4,8,5], 'even') // 1
quadruples([2,4,6,8,10,5], 'even') // 2
quadruples([2,4,6,8,10,5], 'odd') // 0
so far this is where I am at:
function quadruples(givenArray, evenOrOdd) {
let arr = []
if(evenOrOdd == 'even') {
if( i = 0; i < givenArray.length; i++) {
}
};
I figured I need to run a for loop and then use a % operator but I am stuck on where to go from here.
Any help is appreciated!
You need dynamic programming for this with a local and global variable: [2, 4, 6, 8, 10, 5]