Skip to content

Instantly share code, notes, and snippets.

@kironroy
kironroy / mapsIteration.js
Created May 23, 2023 01:49
map iteration js
console.log('----------new map--------------');
const question = new Map([
['question', 'What is the best programming language in the world'],
[1, 'C'],
[2, 'Java'],
[3, 'JavaScript'],
['correct', 3],
[true, 'Correct 😊'],
[false, 'try again'],
@kironroy
kironroy / maps.js
Created May 23, 2023 01:12
maps.js
// maps are more useful then sets
// maps have key-value pairs
// maps keys can have any type
const restaurantMap = new Map();
restaurantMap.set('name', "Vini's Curry House");
restaurantMap.set(1, 'Mumbai, India');
console.log(restaurantMap.set(2, 'Paris, France'));
@kironroy
kironroy / sets.js
Created May 23, 2023 00:52
Sets in js
// sets have no order and only store unique items.
// no need to get data out of a set
const ordersSet = new Set(['Pasta', 'Pizza', 'Risotto', 'Pasta', 'Pizza']);
console.log(ordersSet);
console.log(new Set('Vini'));
@kironroy
kironroy / .js
Created May 21, 2023 20:53
looping objects
const weekDays = ['mon', 'tues', 'wed', 'thu', 'fri', 'sat', 'sun'];
const openingHours = {
[weekDays[3]]: {
open: 12,
close: 22,
},
fri: {
open: 11,
close: 23,
@kironroy
kironroy / optionalChaining.js
Created May 21, 2023 20:33
Optional chaining and nullish coalescing operator
'use strict';
const weekDays = ['mon', 'tues', 'wed', 'thu', 'fri', 'sat', 'sun'];
const openingHours = {
[weekDays[3]]: {
open: 12,
close: 22,
},
fri: {
@kironroy
kironroy / destructuringObjs.js
Created May 20, 2023 03:06
Destructing Objects
'use strict';
// Data needed for a later exercise
const flights =
'_Delayed_Departure;fao93766109;txl2133758440;11:25+_Arrival;bru0943384722;fao93766109;11:45+_Delayed_Arrival;hel7439299980;fao93766109;12:05+_Departure;fao93766109;lis2323639855;12:30';
// Data needed for first part of the section
const restaurant = {
name: "Vini's Curry House",
location: '123 Gora Way, Mumbai, India',
categories: ['Punjabi', 'Bengali', 'Madras', 'Neplai'],
'use strict';
// Data needed for a later exercise
const flights =
'_Delayed_Departure;fao93766109;txl2133758440;11:25+_Arrival;bru0943384722;fao93766109;11:45+_Delayed_Arrival;hel7439299980;fao93766109;12:05+_Departure;fao93766109;lis2323639855;12:30';
// Data needed for first part of the section
const restaurant = {
name: "Vini's Curry House",
location: '123 Gora Way, Mumbai, India',
@kironroy
kironroy / rest.js
Created May 18, 2023 00:58
...REST
// functions REST
const add = function (...numbers) {
let sum = 0;
for (let i = 0; i < numbers.length; i++) sum +=
numbers[i];
console.log(sum);
};
add(2, 3);
add(5, 6, 7, 8, 9);
@kironroy
kironroy / code_challenge_temps.js
Created May 9, 2023 23:27
Code Challenge Temp js
// CODE CHALLENGE
// Given an array of forecasted maximum temperatures, the thermometer displays a
// string with the given temperatures. Example: [17, 21, 23] will print "... 17ºC in 1
// days ... 21ºC in 2 days ... 23ºC in 3 days ..."
// Your tasks:
// 1. Create a function 'printForecast' which takes in an array 'arr' and logs a
// string like the above to the console. Try it with both test datasets.
// 2. Use the problem-solving framework: Understand the problem and break it up
// into sub-problems!
@kironroy
kironroy / for loop backwards.js
Last active May 6, 2023 04:11
for loop backwards and loop within loop
const ginaArr = [
'Gina',
'Davis',
2037 - 1967,
'singer',
['Sam', 'Tam', 'Mam'],
];