From 496f67cdea0e75fd89708aa12925ebfba1d674bc Mon Sep 17 00:00:00 2001 From: Gina Benavidez Date: Thu, 10 Aug 2017 12:35:22 -0700 Subject: [PATCH] remove string question and add question: 'findMostFrequent()' which finds the element in an array which occurs the most --- Arrays/writtenInJavascript.js | 36 ++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/Arrays/writtenInJavascript.js b/Arrays/writtenInJavascript.js index c84e297..ee69af6 100644 --- a/Arrays/writtenInJavascript.js +++ b/Arrays/writtenInJavascript.js @@ -5,12 +5,34 @@ function mergeTwoArrays(arr){ mergeTwoArrays([ ['b', 'a'], ['l', 'z', 'y'] ]); -// - Find out if a given string is a palindrome -function palindrome(str){ - if (str.toLowerCase() === str.toString().toLowerCase().split('').reverse().join('')){ - return true; - } else { - return false; +// given an array of integers, find the number that is repeated the most. +function findMostFrequent(arr){ + var repsCount = {}; + for(i=0; i occursMore){ + occursMore.push(key); + } + } + return occursMore; +} +// I'd especially like to see other approaches to this problem, comment if you have a different approach. + +// - Find all even numbers in array +function evenOnly(array){ + var onlyEven = []; + for (i=0; i