I am attempting to write a “binary search” which I’ve never done before. The code below does not work when the value searched for is 6 or 2 and I want to know what I am doing wrong and how to remedy it. EDIT To explain what it is suppose to do (based on my understanding) a binary search requires that an array is already sorted, it then looks for the mid-point index of an array. For example, if an array had nine indexes (0-8)the the mid point would be index 4. The algorithm then determines if that mid point
i want to get the number with only one repitition: i want to get [1,2,1], but right now i am getting only  Answer Just overwrite your original array using Array.prototype.filter:
I’m trying to write a program that takes an array of edge pairs and turns it into a tree. I’m given a root. In this example, the root is 2. The only constraint is, each node can max have 2 children. Sample input: Expected output: Would look something like this: This is my attempt so far: Feel like this should be pretty simple but I’m missing something.. Any help? 🙂 Answer Wow, I love this question. And is pretty challenging too! This was one of my first time to take a recursive approach to a certain problem. And I think
I am currently having problem on modifying a Json schema, the schema is below: I know this can be done using recursion, and I have tried to fetch the required item(code is below), but I have no idea how to put the required item back into properties and change to boolean value. Thanks in advance. I want to put it into such format: Answer You can use recursive function with for…in loop and update object with required key on any level.