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
Array.prototype.transform = function(fn){ //map | |
let newList = [], i = 0, len = this.length; | |
for(i; i < len; i++){ | |
newList.push(fn(this[i])); | |
} | |
return newList; | |
} | |
Array.prototype.exclude = function(fn){ //filter | |
let filteredList = [], i = 0, len = this.length; |
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 isIt = function(that, type){ | |
return Object.prototype.toString.call(that) === ('[object '+ type + ']') | |
} | |
//Examples | |
isIt([1,2], "Array"); // true | |
isIt(undefined, "Undefined"); // true | |
isIt(true, "String") // false |
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 Calc = function(init){ | |
this.init = init; | |
} | |
Calc.prototype.equals = function(callback){ | |
callback(this.init); | |
} | |
Calc.prototype.add = function(val){ | |
this.init += val; |
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
let deepCopy = function(copied, copy){ | |
let i = 0, len = copy.length; | |
for(i; i < len; i++){ | |
copied[i] = copy[i] | |
} | |
return copied; | |
} |
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
Array.prototype.Every = function(callback){ | |
let i = 0, len = this.length; | |
for(i; i < len; i++){ | |
if(!callback(this[i])){ | |
return false | |
} | |
} | |
return 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
let List = function(){ | |
this.Store = []; | |
this.size = 0; | |
this.pos = 0; | |
} | |
List.prototype.append = function(ele){ | |
this.Store[this.size++] = ele; | |
} |
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
let Singleton = (function(name, yearOfBirth, job, relationship){ | |
let instance; | |
function init(){ | |
return { | |
name: name, | |
age: new Date().getFullYear() - yearOfBirth, | |
job: job, | |
relationship: relationship | |
} |
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' | |
let Stack = function(max){ | |
this.Store = []; | |
this.top = 0; | |
if(typeof max == 'number' && max != NaN){ | |
this.max = max | |
}else{ | |
throw new Error(max + ' should be a number'); |
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
let stack = require("https://gist.github.com/khaled0fares/4ffe7a9db1c4c71b1e361c2c636f0c71");// Link to the stack gist, for calirfication only. | |
let isPalindrome = function(txt){ | |
let len = txt.length, | |
stack = new Stack(len), | |
reversed = "", | |
i = 0; | |
while(!stack.full()){ |
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
let Queue = function(){ | |
this.Store = []; | |
} | |
Queue.prototype.enqueue = function(ele){ | |
this.Store.push(ele); | |
} | |
Queue.prototype.dequeue = function(){ | |
if(this.empty()){ |
OlderNewer