Using the Pythagorean theorem with Java

I’m trying to create this program that essentially solves the 3rd value of a right triangle. So the hypotenuse will always be 1, and one of the values (lets call it ‘x’) will be greater than or equal to -1 but less than or equal to 1. First, I created a loop to include all …

Numpy matrix to array

If you’d like something a bit more readable, you can do this: Equivalently, you could also do: A = np.asarray(M).reshape(-1), but that’s a bit less easy to read.

variably modified array at file scope in C

You can not have static array which size is given as a variable That’s why constants should be #defined: This way preprocessor will replace a with 6, making it valid declaration.

Checking if a key exists in a JavaScript object?

Checking for undefined-ness is not an accurate way of testing whether a key exists. What if the key exists but the value is actually undefined? Expand snippet You should instead use the in operator: Expand snippet If you want to check if a key doesn’t exist, remember to use parenthesis: Expand snippet Or, if you …

What is the best way to delete a value from an array in Perl?

Use splice if you already know the index of the element you want to delete. Grep works if you are searching. If you need to do a lot of these, you will get much better performance if you keep your array in sorted order, since you can then do binary search to find the necessary …

GCC: Array type has incomplete element type

It’s the array that’s causing trouble in: The second and subsequent dimensions must be given: Or you can just give a pointer to pointer: However, although they look similar, those are very different internally. If you’re using C99, you can use variably-qualified arrays. Quoting an example from the C99 standard (section §6.7.5.2 Array Declarators): Question …

Create an empty object in JavaScript with {} or new Object()?

Objects There is no benefit to using new Object(); – whereas {}; can make your code more compact, and more readable. For defining empty objects they’re technically the same. The {} syntax is shorter, neater (less Java-ish), and allows you to instantly populate the object inline – like so: Arrays For arrays, there’s similarly almost no benefit to ever using new Array(); over []; – …

Java says this method has a constructor name

You can’t use the class name as the name for a method. The only “methods” that can share a name with the class are constructors. One fix would be to rename your class from isPalindrome to PalindromeFinder or something. That would also better align with Java naming conventions. EDIT: Note that you never actually called your method in main; …

Print array elements on separate lines in Bash?

Try doing this : The difference between \$@ and \$*: Unquoted, the results are unspecified. In Bash, both expand to separate args and then wordsplit and globbed. Quoted, “\$@” expands each element as a separate argument, while “\$*” expands to the args merged into one argument: “\$1c\$2c…” (where c is the first char of IFS). You almost always want “\$@”. Same goes for “\${arr[@]}”. Always quote them!

Array to Hash Ruby

That’s it. The * is called the splat operator. One caveat per @Mike Lewis (in the comments): “Be very careful with this. Ruby expands splats on the stack. If you do this with a large dataset, expect to blow out your stack.” So, for most general use cases this method is great, but use a …