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
# Taken from here: | |
# https://github.com/creationix/nvm#zsh | |
# place this after nvm initialization! | |
autoload -U add-zsh-hook | |
load-nvmrc() { | |
local node_version="$(nvm version)" | |
local nvmrc_path="$(nvm_find_nvmrc)" | |
if [ -n "$nvmrc_path" ]; then |
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
history | awk '{print $2}' | sort | uniq -c | sort -rn | head -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
/* | |
Write a program that prints the numbers from 1 to 100. But for multiples of three print ‘Fizz’ instead of the number and for the multiples of five print ‘Buzz’. For numbers which are multiples of both three and five print ‘FizzBuzz’. | |
*/ | |
(function fizzBuzz() { | |
console.clear(); | |
const isMutlipleOfThree = (i) => (i % 3 === 0 ) | |
const isMutlipleOfFive = (i) => (i % 5 === 0) |
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
function isSuperset(set, subset) { | |
for (var elem of subset) { | |
if (!set.has(elem)) { | |
return false; | |
} | |
} | |
return true; | |
} | |
function union(setA, setB) { |
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
let a = [1,2,5,1,1,2,8]; | |
// 1. Using for loop | |
let b = []; | |
let len = a.length; | |
for(let i=0; i<len; i++) { | |
if(b.indexOf(a[i]) === -1) { | |
b.push(a[i]); | |
} | |
} |
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
git fetch -p && for branch in `git branch -vv | grep ': gone]' | awk '{print $1}'`; do git branch -D $branch; done |
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
const myObject = Object.create(null); | |
myObject; // {} | |
myObject.test; // undefined | |
Object.prototype.hasOwnProperty.call(myObject, 'test'); // false | |
// Uncaught TypeError: | |
// myObject.hasOwnProperty is not a function | |
myObject.hasOwnProperty('test'); |
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
function firstDuplicate (numArray) { | |
const len = numArray.length; | |
let result = -1; | |
if(len < 2) { | |
return result | |
} | |
let dupArray=[]; |
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
// const inputArr = [4,1,3,14,15,18,39,56,89,101,150,165,187] // output 3 | |
// const inputArr = [9,31,38,5,62,44,38,17,19,38,50,74] // output 5 | |
const inputArr = [5,6,8,9,11,14,16,18,20,25] //output 'null' | |
const smallestPrime = (numArray) => { | |
const inputArr = numArray.slice(); | |
const isPrime = num => { | |
for(let i = 2, s = Math.sqrt(num); i <= s; i++) | |
if(num % i === 0) return false; | |
return num !== 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
function is(type, object) { | |
type = type[0].toUpperCase() + type.slice(1); | |
var toString = Object.prototype.toString; | |
return toString.call(object) === '[object ' + type + ']'; | |
} | |
console.log(is('object', {})); // true | |
console.log(is('array', [])); // true | |
console.log(is('object', [])); // false | |
console.log(is('number', 2)); // true | |
console.log(is('number', '2')); // false |
NewerOlder