I’m trying to write a recursive function that takes two parameters – an integer input, n, and an integer base, m – and returns a string representation of the number in Base m. I’m stuck can someone help? Answer You forgot to include base in recursive call And to reduce complexity, the base case of this recursion call is to
Tag: recursion
Recursion question: Create array where each letter occupies an index of the array
I am using javascript. I am new to recursive functions, and cannot seem to figure out how to express this logic recursively: ” Write a function that accepts a string and creates an array where each letter // occupies an index of the array. ” (Firstly,) I think the question is asking me to do the following: ‘Hello’ -> [‘H’,
How to properly call a recursive function inside a for loop?
I’m trying to implement a method that takes as a parameter: target string and an array with string values in it. The goal is to check if it is possible to construct with array’s value, the given target string.The words in array can be used as many times as we want. Example: As we can see, by concatenating “abc” and
Why is this recursion example giving me an infinite loop?
This is driving me insane. Here is the code : Why is this giving me an infinite loop when it’s supposed to print ‘laugh’ 10 times? Answer Like other answers said, each laugh() created a new local counter. The most appropriate recursive method here is to pass the counter as an argument: This is a pure function approach, reducing the
How to build map for large json with unknown structure
I have large json data with unknown depth and I need to build a map in the following format of result. I think recursion is a good way to solve this but I am not able to implement recursion properly. This is my current progress. Which gives incorrect output. Answer I’m glad to say, you’re on the right track. All
Counting up and down in recursive manner in JS
I am currenty working on functional programming techniques. There are topics about this issue [ especially there is one about java ] but not about JS. I want to create a recursive function that can first, count up until the limit I decide, from the number I indicate and then start counting down when the limit is reached. I can
Recursive counting in arbitrary nested object
I’m attempting to do some data visualization and dealing with this dataset. Object with arbitrary nested objects. I’m trying to count how many times different values appear in a key. This is just a snippet of the dataset, in the original the owns nested objects go 7+ levels deep. Example dataset I’m working with: I’m thinking I’ll have to do
Print path from root to a given node in a tree with multiple children
I am trying to print the path from root to a given node containing value of 2. Each node can have children containing several nodes. Here is a visual reference I have flight data like this: This is the code I wrote so far: So far I’m getting: It seems like it is able to find the node containing the
How to recursively construct an JSON hierarchy from a NodeList?
Given the following input: I want to build an JSON object based on the above input: Here’s what I have tried so far: The result I’m getting is different from what I expect, Here’s the result I am getting: seems that some data are not there, Any idea what I might be missing? Answer fix html First I would remark
Recursively Search in Array with a For Loop
I know there are better ways to search an array, but I really want to understand how to return when the value is found in a recursive call. Logging when found isn’t a problem, but I can’t seem to make this return true when found. The problem is basic. Fully search multi-dimensional array for a value and return true if