Skip to content

Instantly share code, notes, and snippets.

View iuliaL's full-sized avatar
♾️

Iulia Maria Lungu iuliaL

♾️
View GitHub Profile
function canJump(arr,d){
if (arr.length < d){
return true;
}
let pos = -1;
for (let i = 0 ; i < arr.length; i++){
if (arr[i] && i-pos <= d)
pos = i;
}
@iuliaL
iuliaL / <typeahead-search>
Last active May 13, 2017 15:13
typeahead directive angular es6
@iuliaL
iuliaL / removeItemFromArray.js
Last active June 29, 2017 07:08
remove item from array in a declarative way, avoiding array mutations
/*
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)
@iuliaL
iuliaL / integerPower.js
Last active October 24, 2017 08:00
an implementation of positive or negative integer powers
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);
}
}
@iuliaL
iuliaL / isNotMobile.js
Last active October 24, 2017 08:01
check if platform is mobile
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
@iuliaL
iuliaL / revertNames.js
Created October 24, 2017 08:02
REGEX: Using Replace with Captured Groups
let string = "Joaquin Smith";
string.replace(/^(\w+) (\w+)$/, '$2 $1')
=> "Smith Joaquin"
@iuliaL
iuliaL / formatTelephoneNumber.js
Created October 24, 2017 08:46
Regex - format a telefhone number
string = "0727937613";
string.replace(/^(\d{4})(\d{3})(\d{3})$/, "($1) $2-$3");
=> "(0727) 937-613"
@iuliaL
iuliaL / key-del.js
Last active November 9, 2017 18:18
Delete a (nested) key from JSON object
// 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)=> {
@iuliaL
iuliaL / key-del.ts
Last active November 9, 2017 18:20
Delete (nested) keys passed as any number of arguments from JSON object using recursion
"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);
@iuliaL
iuliaL / passPropsDownToRoute.js
Created December 11, 2017 12:52
React router v4: when I want to pass down props in a route to route children
const SynopticRoute = ({ scissor, ...rest })=> {
return (
<Route {...rest} render={(props)=>
<SynopticView scissor={scissor} {...props} />
} />
);
};