The challenge given to me: "Using the JavaScript language, have the function ArrayAdditionI (arr) take the array of numbers stored in arr and return the string true if any combination of numbers in the array can be added up to equal the largest number in the array, otherwise return the string false. rev2023.5.1.43404. Have the function ArrayAddition(arr) take the array of numbers stored in arr and return the string true if any combination of numbers in the array (excluding the largest number) can be added up to equal the largest number in the array, otherwise return the string false. Andr Santiago. Also, there are MANY ways to solve this problem. This allows me to try and see if I can split() my wordToCompare in order to see if I can split it into two words. Are you sure you want to hide this comment? . These are a few answers that I wrote or find clever with explanations of why/how they work, TLDR: explanation of best solution at the bottom of the post and actual solutions at the bottom of each section. This is illustrated in the recursive calls isSum(rest, target - first) || isSum(rest, target), For the base case, when we run out of elements to evaluate, we perform a check to see if the combination of elements subtracted from the current target equals 0. Are you sure you want to create this branch? Thanks for contributing an answer to Stack Overflow! Try it free. I like the tree diagram it made everything clicked for me. Are you sure you want to create this branch? Not the answer you're looking for? We want to get the first array in the array of arrays (the first row) if you dont know how .shift(), .push(), or the spread operator works check out this MDN page but basically it takes the first item in an array. If krtb is not suspended, they can still re-publish their posts from their dashboard. Ask Question Asked 1 year, 9 months ago. Please do share below in the comments. How to insert an item into an array at a specific index (JavaScript). What were the most popular text editors for MS-DOS in the 1980s? coderbyte-js-solutions if(arr.length === 0){ return target === 0 }. How do I include a JavaScript file in another JavaScript file? I am doing a challenge on Coderbyte and I would be grateful for any advice on my question: The challenge given to me: Snail Array Challenge Solution JavaScript Hello Dev World Also use if(result !== largestNum) {, Division is expensive and might have unexpected results with floating-point numbers. How do I check if an array includes a value in JavaScript? Thanks CodeiSir. Code and interview better on the #1 platform for 1M+ developers that want to take their careers to the next level. Once unsuspended, krtb will be able to comment and publish posts again. Or is it possible to manipulate any method(with functions as parameters)? Coderbyte | The #1 Coding Assessment Platform In the body of the nested for loop, an if statement evaluates whether the person number (value of Array element) is greater than the number of the next person in the queue. javascript coderbyte-js-solutions Updated on Dec 21, 2019 JavaScript xgravellx / javascript-algorithm-examples Star 2 Code Issues Pull requests In this repo, you can find examples to improve your Javascript Algorithm knowledge. If true return true and finish the function. This was my approach to solving arrayAddition.