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
// Example: "kjzskjkjk" 3 => [ "kjz", "jzs", "zsk", "skj" ] | |
function justUniqueVals(arr) { | |
return arr.filter((item, index, self) => self.indexOf(item) == index); | |
// not performant for long arrays!!! use occurences hashmap instead | |
} | |
function hasUniqueVals(arr) { | |
const filtered = justUniqueVals(arr); |
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
// transformations as an array of arrow functions | |
// example for transformations of an array, in this case [1,2,3] | |
const pipeline = [ | |
// transformation functions here | |
array => { array.pop(); return array; }, | |
array => array.reverse() | |
]; | |
pipeline.reduce((xs, f) => f(xs), [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
const SynopticRoute = ({ scissor, ...rest })=> { | |
return ( | |
<Route {...rest} render={(props)=> | |
<SynopticView scissor={scissor} {...props} /> | |
} /> | |
); | |
}; |
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"; | |
import _ from 'lodash'; | |
// works with | |
// just key name (i.e 'password', 'tenantName') | |
const recursiveCleaner = (object, keys) =>{ | |
return Object.keys(object).reduce((objectSoFar, key) => { | |
if (object[key] && typeof object[key] === 'object') { | |
objectSoFar[key] = recursiveCleaner(object[key], keys); |
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
// works with just one key to delete (for now) by proving | |
// complete path (i.e 'rows.0.panels.0.password') or | |
// just key name (i.e 'password') | |
import '_' from 'lodash'; | |
const DOT_SEPARATOR = "."; | |
function checkPath(arr, object){ | |
arr.forEach((chunk, index, array)=> { |
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
string = "0727937613"; | |
string.replace(/^(\d{4})(\d{3})(\d{3})$/, "($1) $2-$3"); | |
=> "(0727) 937-613" |
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 string = "Joaquin Smith"; | |
string.replace(/^(\w+) (\w+)$/, '$2 $1') | |
=> "Smith Joaquin" |
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 _isNotMobile (){ | |
let check = false; | |
(function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|k |
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 pow(base,power) { | |
if ( power < 0 ) { | |
return ( 1 / pow( base, -(power)) ); | |
} else if (power == 0){ | |
return 1; | |
} else { | |
return base * pow(base, power - 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
/* | |
remove item from array in a declarative way, | |
avoiding array mutations | |
Instead of splicing | |
*/ | |
// 1. use Array.filter | |
const removeItem = (list,index) => list.filter((item,i) => index !== i) |