New answers tagged

0

My idea is to split text for the lines and then merge them by separating different key/value pairs. Next just parse all pairs from the list. This is similar to what Shelby suggested. Here is the code for complete solution: const joinUntil = (lines, test) => { const index = lines.findIndex(test); const offset = index === -1 ? Infinity : index; ...


-1

You might use a decoding key, an array which has stored the encrypted values for each character, then you use a nested loop construction. This would shorten your code significantly and you might be able to change the encryption key more easily.


1

Regular expressions are a good solution here: They are often more performant than manually messing with indicies and checking values, especially when the logic to implement isn't trivial Their logic is much easier to understand at a glance than a long chunk of code The indicies of each match can be kept track of by checking the length of the full match For ...


-1

Readability Depending on how often this function is going to be called you could opt for a more readable version that may be slightly less performant. Using functions like split and map you could make this pretty simple. Here is an example below. // Start with kvp strings and newline kvp strings. var texts = [ "key1: value1\r\nkey2: value2", ...


3

Use constant variables, not macros. (Perhaps NB_COLOR and NB_CASTLE could be added to the enums). Use enum class instead of a plain enum. en_passant could be translated to the relevant index in the board. Perhaps use std::optional, or a named constant (e.g. -1) for the "no en-passant available" case. Use std::array instead of a plain array for ...


7

Handle malformed FEN The code happily accepts /9/. It doesn't check that the rank spells out exactly 8 files. It doesn't check that the input spells out exactly 8 ranks. In both cases, hello buffer overflow. It also doesn't check that the piece letter makes sense (may be good for the fairy chess. but still ...). fen.substr(iter + 1, 3); looks strange, as it ...


0

I haven’t done much thinking about lexers since I was a university student 14 years ago and was in a compilers class. I have been working with Javascript since then. Overall the code looks well-written. Variables are declared well using const and let appropriately. Many other ES6 features appear to be applied appropriately. Strict comparisons are utilized ...


2

Disclaimer: Not a Code Reviewer Your code looks pretty good! Just briefly commenting: My guess is that maybe you might want to design some low-complexity algorithms to do the parsing (if not using an already developed parser – which would have been my first choice – browsing through GitHub), rather than using operational-intensive string manipulations with ...


1

Rather than using a std::vector and using the indices to specify the host and path, we can create a little struct and refer to the members by name: struct URL { std::string host; std::string path; }; So we can refer to url.host instead of url.at(0). As pointed out in the comments, the parsing method could be more accurate and comprehensive. It's fine ...


Top 50 recent answers are included