hjertnes.blog

#

17.11.2017 01:00

Hello, World

17.11.2017 01:00

Higher order Functions

17.11.2017 01:00

Higher order functions (or components, if you’re using React) is a functions that does at least one out of two thigns. It takes a function as a argument; not its value, but the function itself. Or it returns a function itself; again, not the value from it but the function itself. This might be considered a very exotic topic in many languages, but should be common practice for every JavaScript developer. You are doing this every time you use a callback, a map/filter/reduce or a promise.

```text The short example above are using a higher order function to double each element in the list. And the example below uses a higher order function that returns a function. ```

```text Higher Order Functions, in both forms is a very useful teqnique to avoid a lot of almost identical code. And even more useful when you start to code in React by doing the same thing just by taking components as arguments instead of functions or returning components instead of functions. ```

#

16.11.2017 01:00

Join

16.11.2017 01:00

Join is a method living on the String prototype. All it does is to take a list of strings and combines them into a string, either with or without a dividing character. Very useful if you have a array of something that you want to list out seperated by a comma or something like that. Below is an example, both with Join and I also re-implemented join as a reducer, just because they are so similar; but reduce is far more powerful.

#

15.11.2017 01:00

Seeing people saying they are switching to Firefox makes me wonder: is this 2004?

#

15.11.2017 01:00

#

15.11.2017 01:00

To the untutored eye, Lisp is a strange programming language. In Lisp code there are parentheses everywhere. Some people even claim that the name stands for “Lots of Isolated Silly Parentheses” – An Introduction to Programming in Emacs Lisp

Sorting stuff with Javascript

15.11.2017 01:00

To sort stuff with Javascript is very easy, especially if it is a array of strings or numbers; then you can just do something like this:

```text But if you are sorting something like for example a array of objects or array of arrays, then you need to pass a function to it telling sort how to order the data. It is very easy to do, when you understand how it works. The way it works is that you define a function that recieves two elements, and your function have figure out if they are equal, if the first is larger or if the second is larger.
The short version is: ```

```text
  • return 0 if they are the same
  • return 1 if the first is larger than the last
  • return -1 if the last is larger than the first
  • ```

    ```text Example: ```

    Simple and powerful. You can sort more or less anything with it. But it isn&#8217;t always the best idea. Remember, the sort method <em>HAS</em> side affects, it <em>MUTATES</em> the array you are running it on. </div>
    

    #

    14.11.2017 01:00

    Testing out a new text editor this week. I’m very happy with Spacemacs this far.