Reminds me of Starliner. Politics, oversized management, and bureaucracy are cancer to engineering programs.
Reminds me of Starliner. Politics, oversized management, and bureaucracy are cancer to engineering programs.
The issue is that, in the function passed to reduce
, you’re adding each object directly to the accumulator rather than to its intended parent. These are the problem lines:
if (index == array.length - 1) {
accumulator[val] = value;
} else if (!accumulator.hasOwnProperty(val)) {
accumulator[val] = {}; // update the accumulator object
}
There’s no pretty way (that I can think of at least) to do what you want using methods like reduce
in vanilla JS, so I’d suggest using a for loop instead - especially if you’re new to programming. Something along these lines (not written to be actual code, just to give you an idea):
let curr = settings;
const split = url.split("/");
for (let i = 0; i < split.length: i++) {
const val = split[i];
if (i != split.length-1) {
//add a check to see if curr[val] exists
let next = {};
curr[val] = next;
curr = next;
}
//add else branch
}
It’s missing some things, but the important part is there - every time we move one level deeper in the URL, we update curr
so that we keep our place instead of always adding to the top level.
Yeah personally I haven’t needed jQuery in years.
That’s good for handwriting, but digitally I prefer 𝟶. Either is acceptable though.
As an American this is how I feel. I don’t mind Fahrenheit but for absolutely everything else I desperately wish we’d switch.
I learned that after reading this xkcd and then the list. Which was concerningly recently.
I guess on the bright side it was the only misconception on the list that I had.
I mean yeah, we should absolutely be replacing as much fossil fuel use as we can with existing renewable energy tech. But there’s no reason we shouldn’t also be investing in fusion research, at least as far as I’m aware
Currying is converting a function with n parameters to n functions that each have one parameter. This is done automatically in most primarily functional languages. Then, partial application is when you supply less than n arguments to a curried function. In short, currying happens at the function definition and partial application happens at the function call.
Currently the type of test_increment
is (int, int) -> unit -> unit
. What we want is int -> int -> unit -> unit
. The more idiomatic way would have this function definition:
let test_increment new_value original_value () =
Which would require this change in the callers:
test_case "blah" `Quick (test_increment 1 0);
See, in most primarily functional languages you don’t put parentheses around function parameters/arguments, nor commas between them - in this case, only around and between members of tuples.
I’m not an OCaml person but I do know other functional languages. I looked into Alcotest and it looks like the function after “`Quick” has to be unit -> unit
. Because OCaml has currying, and I think test_increment
already returns unit
, all you should have to do is add an extra parameter of type unit
. I believe that would be done like this:
let test_increment (new_value, original_value) () =
Now the expression test_increment (1, 0)
returns a function that must be passed a unit
to run its body. That means you can change the lambdas to e.g. this:
test_case "blah" `Quick (test_increment (1, 0))
I don’t know OCaml precedence rules so the enclosing parentheses here may not be necessary.
I’d also note that taking new_value
and original_value
as a tuple would probably be considered not idiomatic unless it makes sense for the structure of the rest of your code, especially because it limits currying like we did with the unit
being able to be passed later. Partial application/currying is a big part of the flexibility of functional languages.
Edit: if you’re getting into functional programming you may also consider calling increment_by_one
“succ” or “successor” which is the typical terminology in functional land.
Fantastic, thank you for that
Eh, I’ll take assembly over like Perl any day. I may be biased since I like to reverse engineer though.
Except you remember carefully putting it down in a particular spot so you’ll remember where it is, but you’ve been looking for 10 minutes now and still can’t remember what that spot was
Pretty sure Jython is, though not a Python 3 version. My exposure is as the scripting language, behind Java as the primary language, for Ghidra. And I hate it and installed Eclipse rather than deal with J/Python’s shit.
Ouch! I knew it was bad, being in this transition period to Vulcan, but hearing the numbers really puts it into perspective.
The 20 flight milestone for a single booster is also incredibly impressive. Funny looking back to when booster reuse was considered a fool’s errand. Nice to have some good news for a change.