Skip to content

Instantly share code, notes, and snippets.

// see all console functions
console.log(console);
// 1 view data as table console.table(data, columnNames)
const array = [1, 2, 3, 4, 5];
const object = {
name: "Leira",
lastName: "Sánchez",
twitter: "MechEngSanchez",
};
@coderwurst
coderwurst / Stringify.js
Created January 21, 2020 15:07
JSON Stringify examples
JS Result
EDIT ON
const firstItem = {
title: 'Transformers',
year: 2007
};
console.log(JSON.stringify(firstItem));
const secondItem = {
title: 'Transformers',
@coderwurst
coderwurst / RoughWork.js
Last active January 20, 2020 16:45
Big O Notation Examples
// Calculate the sum of all numbers from 1 - 10
// O(n)
function addUpToOne(n) {
return n * (n +1) / 2;
}
var timeOne = performance.now();
addUpToOne(10000000);
var timeTwo = performance.now();
console.log(`Time taken 2: ${(timeTwo - timeOne) / 1000} seconds`)
@coderwurst
coderwurst / String.js
Last active January 25, 2020 19:23
String examples written in JavaScript
var string = "this is a nice string"
var arrayString = [ ...string.split('')]
arrayString
(21) ["t", "h", "i", "s", " ", "i", "s", " ", "a", " ", "n", "i", "c", "e", " ", "s", "t", "r", "i", "n", "g"]
arrayString.reverse()
(21) ["g", "n", "i", "r", "t", "s", " ", "e", "c", "i", "n", " ", "a", " ", "s", "i", " ", "s", "i", "h", "t"]
var newString = arrayString.toString()
@coderwurst
coderwurst / Arrays.js
Last active January 20, 2020 12:40
Array Examples written in JavaScript
// REMOVE DUPLICATE VALUES
var fruitBasket = ["banana", "apple", "orange", "watermelon", "apple", "orange", "grape", "apple"];
// First method
var uniqueFruits = Array.from(new Set(fruitBasket));
console.log(uniqueFruits);
// (5) ["banana", "apple", "orange", "watermelon", "grape"]
// Second method