This file contains hidden or 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 getProviderInfo = function (provider) | |
{ | |
return new Promise(function (resolve, reject) { | |
var time = ~~(Math.random() * 2000) + 2000; | |
// Make request and get the data, simulate request api, no fail in our case | |
window.setTimeout(function () { | |
This file contains hidden or 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 arr = ['yx', 'kax', 'kolm']; | |
var search = 'kax'; | |
var found = false; | |
if(arr.indexOf(search) !== -1) { | |
found = true; | |
} | |
console.log(found); |
This file contains hidden or 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
[ | |
{ "keys": ["super+alt+t"], "command": "unexpand_tabs", "args" : {"set_translate_tabs" : true} } | |
] |
This file contains hidden or 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 Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains hidden or 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
// simple examle how to deal with arguments in JS | |
function rgb(r, g, b) { | |
return [].slice.call(arguments).map(function (v) { | |
var ret = Math.max(0, Math.min(255, v)).toString(16).toUpperCase(); | |
return (ret.length<2 ? '0' : '') + ret; | |
}).join(''); | |
} |
This file contains hidden or 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
// Kata: http://www.codewars.com/kata/534ffb35edb1241eda0015fe/train/javascript | |
/** | |
* @param cards An array of strings representing each card | |
* @returns number Score of the hand | |
*/ | |
function scoreHand(cards) | |
{ | |
var score = 0; | |
var Acount = 0; | |
cards.map(function(v) { |
This file contains hidden or 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
/** | |
Kata: http://www.codewars.com/kata/521c2db8ddc89b9b7a0000c1/train/javascript | |
Tests: | |
var a1 = [[1,2,3], | |
[4,5,6], | |
[7,8,9]]; | |
var a2 = [1,2,3,6,9,8,7,4,5]; |
This file contains hidden or 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
// kata: http://www.codewars.com/kata/52dd72494367608ac1000416/train/javascript | |
// https://en.wikipedia.org/wiki/Trial_division | |
function isPrime(number) { | |
var start = 2; | |
while (start <= Math.sqrt(number)) { | |
if (number % start++ < 1) return false; | |
} | |
return number > 1; | |
} |
This file contains hidden or 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
// kata: http://www.codewars.com/kata/5324945e2ece5e1f32000370/train/javascript | |
function sumStrings(a, b) { | |
var A = a.split(""); | |
var B = b.split(""); | |
var sum = []; | |
if(B.length === 0) B.push(0); | |
if(A.length === 0) A.push(0); | |
if(A.length >= B.length) { |
This file contains hidden or 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
/** | |
* filter array and keep every value only once | |
* @param array arr input array | |
* | |
* @return array array containing only unique values | |
*/ | |
function arrUnique(arr) { | |
arr = arr.filter(function (val, i, self) { | |
return self.indexOf(val) === i; | |
}); |