Skip to content

Instantly share code, notes, and snippets.

const obj = { a: 1, b: 2, c: 3 };
const omit = (prop, { [prop]: _, ...rest }) => rest;
const newObj = omit('a', obj);
const obj = { a: 1, b: 2, c: 3 };
obj.a = undefined;
function multiplyBy3(x) {
  return x * 3;
}
let x = 2, y = 3;
multiply(x, y);
function multiply(x, y) {
  return x * y;
};
map(arr, el => el * 2);  // наша JavaScript-реализация
arr.map(el => el * 2);   // встроенная реализация
const arr = [...Array(100)].map(e=>~~(Math.random()*100));
function map(arr, func) {
  const mapArr = [];
  for(let i = 0; i < arr.length; i++) {
    const result = func(arr[i], i, arr);
    mapArr.push(result);
function sumCents(array) {
  return '$' + array.reduce((x, y) => x + y) / 100;
}
function sumCents(array) {
  return '$' + array.map(el => el / 100).reduce((x, y) => x + y);
}