Image for post
Image for post
Photo by Mick Haupt on Unsplash

Please remember to import the following namespace in your Repl:

using System.Text;

and use the following two methods as a shorthand for logging to the console:

static void log(object o) 
{
Console.WriteLine(Convert.ToString(o));
}
static void log(Stack<int> s)
{
Console.WriteLine($"[{string.Join(", ", s)}]");
}

Stack<int> Instantiation

var s = new Stack<int>();s.Push(1);s.Push(2);s.Push(3);log(s);                                        // [3, 2, 1]

Pop and Peek

log(s.Pop());                                  // 3log(s.Peek());                                 // 2log(s);                                        // [2, 1]

Contains

log(s.Contains(1));                            // Truelog(s.Contains(3));                            // False

Count and Clear

log(s.Count);                                  // 2s.Clear();log(s);                                        // []

Image for post
Image for post

Please remember to import the following namespace in your Repl:

using System.Text;

and use the following method as a shorthand for logging to the console:

static void log(object o) {
Console.WriteLine(Convert.ToString(o));
}

StringBuilder Instantiation

var sb1 = new StringBuilder();var sb2 = new StringBuilder(1);var sb3 = new StringBuilder("ab");var sb4 = new StringBuilder("cddd", 4);log(sb1.Capacity);                              // 16log(sb2.Capacity);                              // 1

Append and Capacity Doubling

log(sb3.Append("c"));                          // abclog(sb4.Append("e"));                          // cdddelog(sb3.Capacity);                             // 16log(sb4.Capacity);                             // 8

Insert

log(sb3.Insert(1,”&”));                        // a&bc

Remove

log(sb3.Remove(0,2));                          // bc

Replace

log(sb3.Replace(“c”,”d”));                     // bdlog(sb4.Replace("d","f",0,2));                 // cfddelog(sb4.Replace("d","f"));                     // cfffe

StringBuilder as Indexer

for (int i = 0; i < sb3.Length; i++) {
log(sb3[i]);
} // b
// d

Image for post
Image for post
Photo by Mike Petrucci on Unsplash

Array Initialization

var a = new int[2];var b = new int[2]{1,2};int[] c = {1,2};

Late Initialization

int[] d, e;d = new int[2] {1,2};e = new int[] {1,2};

Settings and Accessing Values

log(a[0]);                                  // 0log(a[1]);                                  // 0a[0] = 3;log(a[0]);                                  // 3

Accessing Array Elements in a For Loop

for(int i = 0; i < b.Length; i++) {
log($”{i}: {a[i]}”); // 0: 1
// 1: 2
}

Multi-dimensional Array

var f = new int[3,2] {{1,2},{3,4},{5,6}};int[,] g = {{1,2},{3,4},{5,6}};var h = new int[3,2] {{1,2},{3,4},{5,6}};log(h[0,0]);                                // 1log(h[0,1]);                                // 2log(h[1,0]);                                // 3log(h[1,1]);                                // 4log(h[2,0]);                                // 5log(h[2,1]);                                // 6

Jagged Array

int[][] j = new int[2][]
{
new int[3] {1, 2, 3},
new int[2] {4, 5}

Image for post
Image for post
Photo by Jason Leung on Unsplash

For this drill, we’ll be reusing the following strings:

string s1 = "aa";string s2 = "Aa";string s3 = null;

and this function:

private static void log(object o) {
Console.WriteLine(Convert.ToString(o));
}

Compare

log(string.Compare(s1, s2));                           // -1log(string.Compare(s2, s1));                           // 1log(string.Compare(s1, s2, true));                     // 0log(string.Compare(s1, null));                         // 1

CompareTo

log(s1.CompareTo(s2));                                // -1log(s2.CompareTo(s1));                                // 1log(s1.CompareTo(s3));                                // 1log(s3.CompareTo(s1));                                // 🔥🔥🔥

Concat

log(string.Concat(s1,s2));                             // aaAalog(string.Concat(s1,s3));                             // aa

Contains

log(s1.Contains("a"));                                // Truelog(s1.Contains("A"));                                // Falselog(s1.Contains(s3));                                 // 🔥🔥🔥

StartsWith & EndsWith

log(s1.StartsWith("a")); …

Image for post
Image for post
Photo by Hannes Wolf on Unsplash

Introduction

We traditionally think of classes as blueprints for the creation of objects, where every object is an instance of a class, and classes inherit from other classes.

But in Javascript, the story is a bit different.

Javascript uses prototypical inheritance, which means that every object gets methods and properties from its prototype object.

The keyword class was introduced to Javascript in the ECMAScript 2015 (ES6) standard, which allows us to use the familiar format for creating instances of classes.

For example:

class A {
constructor(x) { this.x = x; }
p() { console.log(this.x); }
};
typeof A; // function
A === A.prototype.constructor; // true
A.prototype.p; // A {}
Object.getOwnPropertyNames(A.prototype); …

Image for post
Image for post
Photo by Ryul Davidson on Unsplash

Introduction

JSON crops up everywhere in a developer's life.

It stands for Javascript Object Notation and is a lightweight, universally understood, and language-independent format for:

  • transporting data between a website and a server and vice-versa i.e. data can only be text, so any Javascript object must first be converted to a JSON string before sending a request to the server.
  • composing message queue objects, allowing two systems to communicate with one and another, which might be written in different programming languages.
  • storing data in a NoSQL document database.
  • application configuration files (an open standard file format).

A JSON object is a collection of name-value pairs, where the name must be a string and the value can be any one of the…


Image for post
Image for post
Photo by Macau Photo Agency on Unsplash

Installing git

Open the terminal with + Space keys, type Terminal, and then press ENTER.


Image for post
Image for post
Photo by Antoine Dautry on Unsplash

Javascript’s Math library, a built-in object, has static properties (significant numbers such as PI and E) and methods for performing mathematical operations.

Starting with the constants, I prefer to destruct individual properties from the Math object as shown below. This saves me needing to prefix every constant with the Math object, which is useful in programs that rely heavily on mathematical formulae — such as pricing an option contract or approximating an integral.

(Note that you could place each of these constants into one pair of curly braces, but for demonstration purposes, I’ve separated them out)

let {E} = Math;                  // 2.718281828459045
let {LN2} = Math; // 0.6931471805599453
let {LN10} = Math; // 2.302585092994046
let {LOG2E} = Math; // 1.4426950408889634
let {LOG10E} = Math; // 0.4342944819032518
let {PI} = Math; // 3.141592653589793
let {SQRT1_2} = Math; // 0.7071067811865476 …

Image for post
Image for post
Photo by Vinicius “amnx” Amano on Unsplash

Introduction

A Javascript array stores one or more values in a single variable, which could be of the same type of different types. For example, we can define an array that tracks the close-of-business stock price of a company over each day of the working week, where all entries are of the same type number:

const prices = [21.2, 21.3, 21.6, 20.9, 21.0];

We can also define an array with different types. …


Image for post
Image for post
Photo by Ernest Brillo on Unsplash

Introduction

Functions are blocks of code, wrapped in curly brackets, which can be executed when it's called. This allows us to reuse code many times to prevent repeating ourselves. Functions take in zero to many arguments and can either return a value or nothing at all.

This function adds two numbers together and returns the result:

function calculateSum(a, b) {
return a + b
};

The next function takes in one argument and returns nothing to the caller:

function logError(e) {
console.log(e)
};

Functions in Javascript can also be used as variables, which get invoked when the variables are used. In this example, we call a function to return a random die roll when printing the number variable to…

About

George Marklow

George is a software engineer, author, blogger, and tech enthusiast who believes in helping others to make us happier and healthier.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store