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
Tag: algorithm
Transform a string from camel case to snake case and vice versa
I would like transform string with uppercase to string with underscore like : And conversely : I use Typescript, but I think for that, there is no difference with the Javascript. Thank’s in advance. Jérémy. Answer
Splitting an array in equal parts
I am looking for a Javascript Algorithm to split an array into chunks, but avoiding any small left overs. For example: But I want this: So basically the output is spread over several arrays with a maximum number of elements passed in as second argument. Answer You should recalculate the size, which might need to be smaller than given. Then
Codility Ladder javascript – not understanding a detail that jumps the answer from 37 to 100%
I’m trying to solve all the lessons on codility but I failed to do so on the following problem: Ladder by codility I’ve searched all over the internet and I’m not finding a answer that satisfies me because no one answers why the max variable impacts so much the result. So, before posting the code, I’ll explain the thinking. By
Maximum Subarray (Kadane’s algorithm approach)
https://leetcode.com/problems/maximum-subarray/description/ Input test case: [-2,1,-3,4,-1,2,1,-5,4] [-2, -1] [-2, 1] [1] [1, 2] I wanted to pass this case Input: [-2, -1] so that I modified var currentMax = 0; and var max = 0; to current code. Apparently, Kadane’s algorithm is needed to include at least one positive number so that second case might not be solved by this. Is
Javascript: adjacent Elements Product algorithm
I’m trying to solve a basic javascript algorithm and i’m kinda stuck, here is the question: Given an array of integers, find the pair of adjacent elements that has the largest product and return that product. Example For inputArray = [3, 6, -2, -5, 7, 3], the output should be adjacentElementsProduct(inputArray) = 21. 7 and 3 produce the largest product.
Assigning values to html elements and reading it
I’m trying to make tic-tac-toe game, basing just on html, CSS and pure js. I have already base of game (there is one bug), but I have problem to detect once someone wins. I’ve decided to use MagicSquare algorithm, but I don’t have idea how to attach value to each td element. Here you can find, what I have at
How to create a binary search with recursion
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
Combine json arrays by key, javascript
I need to combine two json arrays, delivered by two rest services. The entries with the same “id” belong together. I need a combined/copied/cloned json array in javascript in the following way (my model in angular2): Is there a way to combine them? The parameter names are not defined exactly and it needs to work with variable parameter vectors. I
Checking if a Binary Search Tree is Valid javascript
I came across this problem online and I found the following function to check if a BST is valid. However, what I don’t fully understand is how max/min change from null to values that you can compare against. so in the following function: when you come back up from the lowest depth on the left it compares the value at