Skip to content

Instantly share code, notes, and snippets.

View luc4leone's full-sized avatar
💭
🗻

Luca Leone luc4leone

💭
🗻
  • Italy
View GitHub Profile
@luc4leone
luc4leone / and-or-operators-as-if-statements.js
Last active June 1, 2020 11:13
Useful way to read JavaScript AND and OR expressions
// I find it useful to read expr1 && expr2 as "if expr1 is true, than expr2"
// By definition, expr1 && expr2 returns expr2 if expr1 can be converted to true; otherwise, it returns expr2.
// Seeing things through an if statement helps me build this sort of mental shortcut.
function and(expr1, expr2) {
if (Boolean(expr1) === true) {
return expr2;
}
return expr1;
}
@luc4leone
luc4leone / map(parseInt).js
Last active September 30, 2019 10:40
['1', '2', '3'].map(parseInt)
// ['1', '2', '3'].map(parseInt) returns [1, NaN, NaN]; why?
// simplified `map`, to be able to step into the code through the debugger
function map(array, callback) {
var mappedArray = [];
for (var i = 0; i < array.length; i++) {
mappedArray[i] = callback(array[i], i, array);
}
return mappedArray;
}
@luc4leone
luc4leone / jake-copyWithin-revisited-v1.js
Last active August 28, 2019 15:27
A commented and edited version of Jake Ryan `copyWithin` version of the native js method
// jake you forgot the end parameter, added!
function copyWithin(originalArray, target, start, end) {
var originalLength = originalArray.length;
var elementsToCopy = [];
// the vars I need to break down the problem
var copyFrom, copyTo, pasteFrom, pasteTo;
// set copyFrom
// if undefined let's set it to 0
@luc4leone
luc4leone / copyWithin.js
Created February 22, 2019 16:27
copyWithin
function copyWithin (array, startPasting, startCopying, endCopying) {
/* TYPE ERRORS */
// no arguments passed in
if (arguments.length === 0) {
throw new TypeError('undefined is not an array');
}
// The following is taken from underscore.js. Basically it checks if the length property of arguments[0] is there
var shallowProperty = function (key) {
return function (obj) {
@luc4leone
luc4leone / edit.js
Created January 8, 2019 05:33
Todo mvc js edit method
edit: function (event) {
var labelEl = event.target;
var liEl = labelEl.closest('li');
var inputEl = liEl.lastElementChild;
var len = inputEl.value.length;
liEl.className = 'editing';
inputEl.focus();
inputEl.setSelectionRange(len, len);
(function() {
var libraryStorage = {};
function loadLibrary(libraryName, dependencyNames, addLibrary) {
var dependencyValues = [];
if (dependencyNames.length !== 0) {
dependencyValues = dependencyNames.map(function(dependencyName) {
return libraryStorage[dependencyName];
})
}
@luc4leone
luc4leone / runWithDebugger.js
Last active March 30, 2017 08:20
my solution to Watch and Code challenge #1: 'Improving runWithDebugger'
// my solution
// I copied the name of the first parameter from Ben Baik solution because
// it's a great choice. Maybe it's redundant because 'runWithDebugger' is
// already meaningful. I take no risk: redundant maybe, but superclear! :-)
function runWithDebugger(functionToDebug, functionToDebugArgs) {
debugger;
functionToDebug.apply(null, functionToDebugArgs);
}
<RecordType id="002">
<NameSize>A</NameSize> <!--Taglie componenti codice-->
<CodeSize>48@M1#1,50@M1#1</CodeSize> <!--Taglie componenti-->
<MarkerName>A.gbr</MarkerName> <!--Nome del marker-->
<Length>101</Length> <!--Lunghezza del marker in cm-->
<OverlapsMarker>34,45</OverlapsMarker> <!--splice in cm-->
</RecordType>
' CICLO TACCHE ---------------------------------------------------------------------------------------------------------
strNotches = ""
Dim dvNotches As New DataView(gdtSegment)
dvNotches.RowFilter = "IdPattern = " & shtCSVPattern & " AND SegType = 10"
dvNotches.Sort = "SegSeq"