delta in matlab in javascript

In MATLAB, the delta function is defined as:

index.tsx
function d = delta(n)
    d = (n==0);
end
42 chars
4 lines

In JavaScript, you can define the delta function using the same logic:

index.tsx
function delta(n) {
    return (n == 0) ? 1 : 0;
}
51 chars
4 lines

Here, the ternary operator is used to check if n is equal to 0. If it is, the function returns 1; otherwise, it returns 0.

related categories

gistlibby LogSnag