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
/* | |
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) |
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 typeaheadSearch() { | |
'ngInject'; | |
return { | |
restrict: 'AE', | |
scope: { | |
items: '=', | |
onInput: '&', | |
getQuestion: '&', | |
getQuestionsSet: '&', | |
loading: '=', |
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 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; | |
} |
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
This is a demo task. | |
A zero-indexed array A consisting of N integers is given. An equilibrium index of this array is any integer P such that 0 ≤ P < N and the sum of elements of lower indices is equal to the sum of elements of higher indices, i.e. | |
A[0] + A[1] + ... + A[P−1] = A[P+1] + ... + A[N−2] + A[N−1]. | |
Sum of zero elements is assumed to be equal to 0. This can happen if P = 0 or if P = N−1. | |
For example, consider the following array A consisting of N = 8 elements: | |
A[0] = -1 | |
A[1] = 3 |
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
.full-height | |
height: 100% | |
.inline-block | |
display: inline-block | |
.block | |
display: block | |
=uppercase |
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 calcWhiteSpaces(limit) { | |
var whitespace = " "; | |
for ( var i= 0 ; i < limit ; i++){ | |
whitespace += " " | |
} | |
return whitespace; | |
} | |
function calcBranchWidth(limit) { | |
var draw = ""; |
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 log --shortstat --pretty="%cE" | sed 's/\(.*\)@.*/\1/' | grep -v "^$" | awk 'BEGIN { line=""; } !/^ / { if (line=="" || !match(line, $0)) {line = $0 "," line }} /^ / { print line " # " $0; line=""}' | sort | sed -E 's/# //;s/ files? changed,//;s/([0-9]+) ([0-9]+ deletion)/\1 0 insertions\(+\), \2/;s/\(\+\)$/\(\+\), 0 deletions\(-\)/;s/insertions?\(\+\), //;s/ deletions?\(-\)//' | awk 'BEGIN {name=""; files=0; insertions=0; deletions=0;} {if ($1 != name && name != "") { print name ": " files " files changed, " insertions " insertions(+), " deletions " deletions(-), " insertions-deletions " net"; files=0; insertions=0; deletions=0; name=$1; } name=$1; files+=$2; insertions+=$3; deletions+=$4} END {print name ": " files " files changed, " insertions " insertions(+), " deletions " deletions(-), " insertions-deletions " net";}' |
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 validateEmail(email) { | |
return /.+@.+/.test(email); | |
} | |
$("form").on("submit", function(event){ | |
var inputArray = $(this).find("input"); | |
var valid = true; | |
inputArray.each(function(index,input){ | |
if(input.attr("required") !== undefined && !input.val()){ |
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 strict'; | |
class Student { | |
constructor({ firstName, lastName, age, interestLevel = 5 } = {}) { | |
this.firstName = firstName; | |
this.lastName = lastName; | |
this.age = age; | |
this.interestLevel = interestLevel; | |
} | |
get name(){ |
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 strict'; | |
function myFunction (name, iceCreamFlavor) { | |
console.log(`${name} really likes ${iceCreamFlavor} ice cream.`) | |
} | |
const flavours = [ 'Banana', 'Lemon'] | |
const lovedFlavours = [ "Straciatella", ...flavours] // this is the same as .concat() | |
const args = ['Iulia', lovedFlavours ]; |