Log in
Sign up
Overview Questions Answers

suparman21

    Stats

    • 131 reputation
    • 38 questions asked
    • 67 answers
    • 34 selected answers
    Overview Questions Answers
    • Newest Questions 38
    Convert a title cased string into a URL string with dashes? With special characters removed?
    Asked 6 months ago by suparman21 · Answeredjavascriptstrings
    2
    What does a doctype do in an HTML document?
    Asked 6 months ago by suparman21 · Answeredhtml
    1
    Extract the domain from a full URL using JavaScript?
    Asked 6 months ago by suparman21 · Answeredjavascript
    2
    How to use the lodash NPM package in Node.js?
    Asked 6 months ago by suparman21 · Answerednode.jslodash
    2
    Function that takes any string and returns it with the 1st character as upper-case?
    Asked 6 months ago by suparman21 · Answeredjavascriptstrings
    2
    View more →
    • Newest Answers 67
    Pull in new remote branches to a local development environment using Git?

    You fetch remote branches with this command:

    git fetch origin
    

    Then the remote branches should show up locally:

    git branch -a
    
    Answered 3 months ago by suparman21 · Selected answer
    Remove any spaces from the start and/or end of a string?

    You can apply a replace() method on your string with a regular expression:

    string.replace(/^[ ]+|[ ]+$/g, "");
    

    It will remove any leading/trailing spaces from your string.

    Here's how you'd use it:

    let string = "  Your string.  "
    string = string.replace(/^[ ]+|[ ]+$/g, "");
    
    // "Your string."
    
    Answered 4 months ago by suparman21
    Get the current version of NPM via the command line?

    Yes, you can do this via the command line:

    npm --version
    

    Which will output the current version number of NPM on your machine:

    8.5.1
    
    Answered 4 months ago by suparman21 · Selected answer
    Get the current version of Node.js on macOS?

    NPM has a version command that lists out versions of NPM packages on your machine:

    npm version
    

    That will output something similar to this:

    {
      test: '1.0.0',
      npm: '8.5.1',
      node: '17.6.0',
      v8: '9.6.180.15-node.13',
      uv: '1.43.0',
      zlib: '1.2.11',
      brotli: '1.0.9',
      ares: '1.18.1',
      modules: '102',
      nghttp2: '1.45.1',
      napi: '8',
      llhttp: '6.0.4',
      openssl: '3.0.1+quic',
      cldr: '40.0',
      icu: '70.1',
      tz: '2021a3',
      unicode: '14.0',
      ngtcp2: '0.1.0-DEV',
      nghttp3: '0.1.0-DEV'
    }
    
    Answered 4 months ago by suparman21
    Randomly shuffle the order of an array in JavaScript?

    Another function you could use:

    function shuffle(array) {
      for (var i = array.length - 1; i > 0; i--) {
          var j = Math.floor(Math.random() * (i + 1));
          var temp = array[i];
          array[i] = array[j];
          array[j] = temp;
      }
    
      return array
    }
    

    It's an implementation of the Durstenfeld Shuffle.

    Answered 4 months ago by suparman21
    View more →
    • Terms
    • Privacy

    © 2022 Chunkks