Skip to content

Instantly share code, notes, and snippets.

View valerymelou's full-sized avatar
:octocat:
Angular ❤️

Valery Melou valerymelou

:octocat:
Angular ❤️
View GitHub Profile
// Example 1
const order = [20.17, 18.67, 1.50, "cheese", "eggs", "milk", "bread"];
const [total, subtotal, tax, ...items] = order;
console.log(total, subtotal, tax, items); // 20.17 18.67 1.5 ["cheese", "eggs", "milk", "bread"]
// Example 2
function sum(...nums) {
let total = 0;
for(const num of nums) {
total += num;
// Example 1
const books = ["Don Quixote", "The Hobbit", "Alice in Wonderland", "Tale of Two Cities"];
console.log(...books); // Don Quixote The Hobbit Alice in Wonderland Tale of Two Cities
// Example 2
const primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29];
console.log(...primes); // 2 3 5 7 11 13 17 19 23 29
// Example 3
const fruits = ["apples", "bananas", "pears"];
Array.prototype.decimalfy = function() {
for (i = 0; i < this.length; i++) {
this[i] = this[i].toFixed(2);
}
};
const digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
for (const digit of digits) {
console.log(digit);
const digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
for (const digit of digits) {
if (digit % 2 === 0) {
continue;
}
console.log(digit);
}
/**
const digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
for (const digit of digits) {
console.log(digit);
}
/**
0
1
2
Array.prototype.decimalfy = function() {
for (var i = 0; i < this.length; i++) {
this[i] = this[i].toFixed(2);
}
};
var digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
for (var index in digits) {
console.log(digits[index]);
var digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
for (var index in digits) {
console.log(digits[index]);
}
/**
0
1
2
var digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
for (var i = 0; i < digits.length; i++) {
console.log(digits[i]);
}
/**
0
1
2
const firstName = "John";
const lastName = "Doe";
const birth = 1980;
const death = 1990;
const person = {
firstName,
lastName,
age() {
return death - birth;
const firstName = "John";
const lastName = "Doe";
const age = 10;
const person = {
firstName,
lastName,
age,
}