Skip to content

Instantly share code, notes, and snippets.

// Array destructuring. Swap values
let param1 = 1;
let param2 = 2;
//swap and assign param1 & param2 each others values
[param1, param2] = [param2, param1];
console.log(param1); // 2
console.log(param2); // 1
// spread operator examples
let a = [3, 4, 5];
let b = [1, 2, ...a, 6];
console.log(b);
function foo(a, b, c) { console.log(`a=${a}, b=${b}, c=${c}`)}
let data = [5, 15, 2];
foo( ...data);
@rafagarcia
rafagarcia / async-await-vs-promises-errors.js
Created December 4, 2018 16:45 — forked from k-vosswinkel/async-await-vs-promises-errors.js
Playing with promises and async/await
const returnsAPromise = (string) => (
new Promise((resolve, reject) => {
if (typeof string !== 'string') reject('Not a string!');
resolve(`String is a resolved promise now: ${string}`);
})
);
const myString = "Kait's string";
let isOurPromiseFinished = false;
@rafagarcia
rafagarcia / gist:645d94057ff14b14853563d001a7872e
Created March 29, 2022 15:41 — forked from CrookedNumber/gist:8964442
git: Removing the last commit

Removing the last commit

To remove the last commit from git, you can simply run git reset --hard HEAD^ If you are removing multiple commits from the top, you can run git reset --hard HEAD~2 to remove the last two commits. You can increase the number to remove even more commits.

If you want to "uncommit" the commits, but keep the changes around for reworking, remove the "--hard": git reset HEAD^ which will evict the commits from the branch and from the index, but leave the working tree around.

If you want to save the commits on a new branch name, then run git branch newbranchname before doing the git reset.

@rafagarcia
rafagarcia / nvmCommands.js
Created April 12, 2022 10:47 — forked from chranderson/nvmCommands.js
Useful NVM commands
// check version
node -v || node --version
// list installed versions of node (via nvm)
nvm ls
// install specific version of node
nvm install 6.9.2
// set default version of node