summaryrefslogtreecommitdiffstats
path: root/scratch.js
blob: 0e2de0a938183b631a111aaad106fb14c18873c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// to run currently open .js file in VSCode, hit 'Run->Run Without Debugging' (Ctrl+F5)
// Node.js needs to be installed, .js file needs to be opened from folder

/*
{
    "version": "2.0.0",
    "tasks": [
      {
        "label": "Show in console",
        "type": "shell",
        "command": "node ${file}",
        "group": {
          "kind": "build",
          "isDefault": true
        },
        "presentation": {
          "reveal": "always",
          "clear": true,
          "echo": false,
          "showReuseMessage": false
        }
      }
    ]
  }
*/

//console.log(String('hello lmao wtf').split('.'));
const sumArray = (arr) => arr.reduce((prev, curr) => prev + curr);
myArr = [3, 7, 9, 12];
console.log("the sum of %O array is: %d", myArr, sumArray(myArr));

console.log("%s is %d years old", 'Jesus', 33);
console.log("%chello, %cworld%c!", "color: blue;", "font-size: 2em;", "/* no CSS rule /*");

// class-like object
function Person(name) {
  this.name = name;  // public data member
  var _age;          // private data member

  function privFunc() {}
  this.setAge = function(n) { _age = n; }
  this.getAge = function() { return _age; } // this.age would be undefined age is 'var'ed'
}
Person.prototype.funkyName = function() { return this.name + 'ley' } // public method to all
var kyle = new Person("Kyle");
console.log(kyle.funkyName());

// convert list to array
function list() {
  return Array.prototype.slice.call(arguments)
}
let list1 = list(1, 2, 3) // will get converted to [ 1, 2, 3 ]
console.log(list1);

// split string into words
var str1 = "this is a string, ayy";
var words = str1.split(/,| /).map(w => console.log(w));

// .format() implement into built-in String object
String.prototype.format = function() {
  var formatted = this;
  for (var arg in arguments) { //
    console.log("arg is %s", arg);
      formatted = formatted.replace("{" + arg + "}", arguments[arg]);
  }
  return formatted;
};
console.log("{0} is dead, but {1} is alive!".format("ASP", "ASP.NET"));

// .format implement into built-in String object using ES6 declarative approach
String.prototype.format = function() {
  return [...arguments].reduce((p,c) => p.replace(/%s/,c), this);
};
console.log('Is that a %s or a %s?... No, it\'s %s!'.format('plane', 'bird', 'SOman'));

console.log((function(){}).constructor);


fetch('https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=MSFT&apikey=demo').then(res => {
  return res.json();
}).then(price => console.log(price));


const { getName } = require('./mymodule');
console.log(getName());

console.log("ayy lmao".toUpperCase());