This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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", | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JS Result | |
EDIT ON | |
const firstItem = { | |
title: 'Transformers', | |
year: 2007 | |
}; | |
console.log(JSON.stringify(firstItem)); | |
const secondItem = { | |
title: 'Transformers', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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`) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |