Posts

  • String Slicing in JavaScript and Python

    I am posting this so that you don’t scratch your head with string slicing in JavaScript like me if you are coming from a Python background.

    I spent some gray cells today while working on a capitalize function in JavaScript. The function simply takes a word as an input and capitalizes it.

    I thought that since a string is an iterable, I could slice it with the indexes. So, I can get index 0, convert it to upper case, and then add [1:] as the remainder of the word.

    Unfortunately that trick from Python did not work in JavaScript; Python’s [start_index:end_index] does not work. JavaScript only allows to access one index, not a range.

    Therefore, the JavaScript method that we need to use is the slice(start_index, end_index). But since JavaScript does not figure out the end_index automatically, we need to get it by the string.length method.

    function capitalize(word){
    return word[0].toUpperCase() + word.slice(1, word.length);
    }
  • Loops in Python and JavaScript

    I’m juggling between JavaScript and Python (C for only Arduino) and sometimes I cannot wrap my head around the syntaxes, so I decided that it will be a good idea to create a table to refer to when I’m using different languages.

    As a refresher,

    • do is an entry loop, which is the condition is evaluated and the loop is started if the condition is true.
    • do-while is an exit loop; the loop is executed at least once, even if the condition never evaluates to true. Until the exit condition is met, the loop runs.

    Note here that Python does not have an explicit do-while construct. Therefore we “trick” Python by starting while true, which always evaluates to true and then specify the exit condition.

  • JavaScript: Function Declarations vs Function Expressions

    I am working on my JavaScript notes and will publish the ones that I think will benefit a larger audience.

    This post is my notes on function declarations, function expressions and arrow functions and when to use each one.

  • Office Scripts: Getting Values in Range

    I’m working on an Office Script on Microsoft Excel and trying to understand what is happening.

    I have an Excel workbook where I am trying to get the values in a range to an array. The range is 98 columns with varying number of rows, and contains duplicate values accross the cells. The range contains 2248 values, and I need to reduce them to unique values to further use in the code.

    The steps are:

    1. Get all the values in the range to an array,
    2. Make sure the array contains only the unique values.

    Step 1

    The most efficient way to get the values in this range would be using the getValues() function on the range:

  • Jekyll install on WSL2 on Windows 11

    OK, I finally bit the bullet and decided to go with a static site generator.

    I looked around on how to best go with Github Pages - Jekyll setup and saw that there were many references to setting Jekyll up on Linux, but I was thinking why wouldn’t I go with WSL2 on my Windows box?

    I managed to do that and got Jekyll working. Here are the steps that I took:

subscribe via RSS