Skip to content

Instantly share code, notes, and snippets.

View sandrabosk's full-sized avatar
👩‍💻
Always a student, never a master. Have to keep moving forward. ~C.Hall

Aleksandra Bošković sandrabosk

👩‍💻
Always a student, never a master. Have to keep moving forward. ~C.Hall
  • Ironhack
View GitHub Profile
// npm i axios
const axios = require('axios');
function getCountryDetails(name) {
return axios
.get(`https://restcountries.eu/rest/v2/name/${name}`)
.then(res => res.data);
}
// ************************************************************************************
// https://www.codewars.com/kata/54f9f4d7c41722304e000bbb/javascript
// Find the first character that repeats in a String and return that character.
// firstDup('tweet') => 't'
// firstDup('like') => undefined
// This is not the same as finding the character that repeats first. In that case,
// an input of 'tweet' would yield 'e'.
// ************************************************************************************
// Sort students by best score and list best 3 as fistPlace, secondPlace, thirdPlace.
// Add everyone else in the array.
const students = [
{
name: 'ana',
score: 5.4
},
{
name: 'ivan',
// Sort students by best score and list best 3 as fistPlace, secondPlace, thirdPlace.
// Add everyone else in the array.
const students = [
{
name: 'ana',
score: 5.4
},
{
name: 'ivan',
// ************************************************
// ************** Rest parameter ******************
// ************************************************
// Reminder: 'arguments' represents a special array-like object that contains all arguments by their index.
function add1() {
let sum = 0;
for (let i = 0; i < arguments.length; i++) {
sum += arguments[i];
// ************************************************
// ************** Spread operator *****************
// ************************************************
// Merging arrays
const reptiles = ['snake', 'lizard', 'alligator'];
const mammals = ['puppy', 'kitten', 'bunny'];
// ES5 approach:
// ************************************************
// ******* Destructuring function parameters *****
// ************************************************
function getFullName(user) {
return `${user.firstName} ${user.lastName}`;
}
getFullName({ firstName: 'ana', lastName: 'martinez' }); // => ana martinez
// ************************************************
// *********** Mixed destructuring ****************
// ************************************************
const customer = {
name: {
firstName: 'ivan',
lastName: 'zoro'
},
age: 32,
// 1: What would be expected outputs and why?
// a:
const [a, b] = [1];
console.log(a * b); // <== NaN
// b => undefined
// 1 * undefined = NaN
// b:
const [a, b = 1] = [2];
// 1: What would be expected outputs and why?
// a:
const [a, b] = [1];
console.log(a * b); // <== ???
// b:
const [a, b = 1] = [2];
console.log(a * b); // <== ???