This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* when there is no difference in apply and call */ | |
// 1. | |
var func = function(arr, barr, carr){ | |
this.arr = arr; | |
console.log(typeof(arr), arr.length, arr, barr, carr); | |
}; | |
func.call(null, 1, 2, 3); // number undefined 1 2 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var x = 1; | |
var A = { | |
x : 10, | |
get: function(){ return this.x; } | |
}; | |
var a = A.get; | |
console.log(a()); // 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Namer(){ | |
console.log(this instanceof Namer); | |
} | |
Namer(); // false | |
new Namer(); // true | |
Namer.call(Namer.prototype); // false | |
Namer.call(new Namer); // true true | |
Namer.call(Namer); // false | |
Namer.call(Object.create(Namer.prototype)); // true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
class Solution { | |
static void Main(String[] args) { | |
var numbers = Console.ReadLine().Split(' '); | |
var x = int.Parse(numbers[0]); | |
var y = int.Parse(numbers[1]); | |
Console.WriteLine(gcd(x, y)); | |
} | |
static int gcd(int x, int y){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log("1,2,3,4".split('')) | |
["1", ",", "2", ",", "3", ",", "4"] | |
console.log("1,2,3,4".split(',')) | |
["1", "2", "3", "4"] | |
console.log("1,2,3,4".split()) | |
["1,2,3,4"] | |
console.log("1 2 3 4".split()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function convertPM(time){ | |
if(time.startsWith('12')){ | |
return time.replace('PM',''); | |
} | |
return (parseInt(time.split(':'))+12) + time.substring(2, time.length-2); | |
} | |
function convertAM(time){ | |
if(time.startsWith('12')){ | |
return '00'+time.substring(2, time.length-2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | |
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var Person = function Person(name, age, sex, friends) { | |
var self = this !== undefined ? this : Object.create(Person.prototype); | |
self.Name = name; | |
self.Age = age; | |
self.Sex = sex; | |
self.Friends = friends; | |
self.SayHelloToMyFriends = function () { | |
var _this = this; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
console.log("arr: ", arr); | |
let even = arr.filter(x => x%2 === 0); | |
console.log("evens: ", even); | |
let odd = arr.filter(x => x%2 === 1); | |
console.log("odds: ", odd); | |
let gt5 = arr.filter(x => x > 5); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ES 2015 | |
var DefaultPerson = { | |
name : { first: "John", last: "Smith"}, | |
age: 25, | |
city: { hometown: "NY", current: "PA" } | |
}; | |
var Person = { | |
name : { first: "EcmaScript", last: "Hacker"}, | |
age: 17, |
NewerOlder