Commit 2530996c authored by Raquel's avatar Raquel 💬

week2/day3

parent c67f510d
......@@ -42,4 +42,7 @@ console.log(set.insert({ week: 2 }))
console.log(set.remove([0].key))
console.log(set.has("hello"))
console.log(set.all())
console.log(set.length())
\ No newline at end of file
console.log(set.length())
// Constructor to initialize the queue
//considering queue front =end of array, and queue back = beginning of array
//here using array but with big amounts of data, better to use linked lists, since arrays are O(n) to push and pop; would have to be a bidrectionally linked list, since we are pushing and poping.
const Queue = function (array) {
this.array = array
}
......
......@@ -8,6 +8,7 @@ const Stack = function (array) {
Stack.prototype.push = function (element) {
this.array = this.array.concat(element)
return this.array
}
// Removes the top most element from the stack and returns that element
......
function invert(obj) {
newObj = {}
for (let key in obj) {
let a = obj[key] // this will assign object value of given key of obj to "a"
newObj[a] = key // this will say that the value of given key of obj is actually equal to key in newObj
}
return newObj
}
console.log(invert({ a: 3, b: 2 })) // { 2: 'b', 3: 'a' }
\ No newline at end of file
function merge(...obj) {
let newObj = {}
for (let x of obj) { // iterates through all objects inputted as arguments as an array
//console.log(x)
for (let key in x) { // iterates through each object in the array
if (!(newObj[key])) {
newObj[key] = x[key]
//console.log(key)
//console.log(x[key])
}
}
}
return newObj
}
console.log(merge({ a: 3, b: 2 }, { a: 2, c: 4 })) // { a: 3, b: 2, c: 4 }
//console.log(merge({ a: 3, b: 2 }, { a: 2, c: 4 }, { e: 8, c: 5 }))
\ No newline at end of file
function myEach(array, fn) {
for (let i = 0; i < array.length; i++) {
(fn(array[i]))
}
}
console.log(myEach([1, 2, 3], function multiplyByTwo(arg) {
return arg * 2
}))
\ No newline at end of file
function myFilter(array, fn) {
newArray = []
for (let i = 0; i < array.length; i++) {
if (fn(array[i])) {
newArray.push((array[i]))
}
}
return newArray
}
console.log(myFilter([1, 2, 3], function biggerThanOne(arg) {
if (arg > 1) {
return true
}
}))
\ No newline at end of file
function myMap(array, fn) {
newArray = []
for (let i = 0; i < array.length; i++) {
newArray.push(fn(array[i]))
}
return newArray
}
console.log(myMap([1, 2, 3], function multiplyByTwo(arg) {
return arg * 2
}))
\ No newline at end of file
function objectKeys(obj) {
keyArray = []
for (let key in obj) {
keyArray.push(key)
}
return keyArray
}
const obj1 = {
'keyCode': 'JS',
2: 'Program Paradigm',
Target: 'Browser',
};
console.log(objectKeys(obj1))
\ No newline at end of file
//simialr to object keys
function objectValue(obj) {
valueArray = []
for (let key in obj) {
valueArray.push(obj[key])
}
return valueArray
}
const obj1 = {
'keyCode': 'JS',
2: 'Program Paradigm',
Target: 'Browser',
};
console.log(objectValue(obj1))
\ No newline at end of file
This diff is collapsed.
function intersect(array1, array2) {
intersectRect = []
if (Math.max.apply(null, array1[0]) > Math.max.apply(null, array2[0])) {
intersectRect.push(array1[0])
console.log(Math.max.apply(null, array1[0]))
console.log(intersectRect)
}
else if (Math.max(array2[0]) > Math.max(array1[0])) {
intersectRect.push(array2[0])
}
else if (Math.max(array1[1]) < Math.max(array2[1])) {
intersectRect.push(array1[1])
}
else if (Math.max(array2[1]) < Math.max(array1[1])) {
intersectRect.push(array2[1])
}
return intersectRect
}
console.log(intersect([[1, 1], [4, 3]], [[2, 2], [6, 7]])) // => [2, 2], [4, 3]
//console.log(intersect([[2, 1], [4, 4]], [[1, 1], [8, 8]])) // => [2, 1], [4, 4]
\ No newline at end of file
node_modules
\ No newline at end of file
function isString(string) {
if (typeof string === "string") {
return true
}
else { return false }
}
console.log(typeof "")
module.exports = {
isString
};
\ No newline at end of file
const asciify = require('asciify'); // this is how we can import external modules in Node
asciify('Awesome', function (err, res) { console.log(res) });
\ No newline at end of file
This diff is collapsed.
{
"name": "testing",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "nodemon test.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"asciify": "^1.3.5",
"nodemon": "^1.19.0",
"tape": "^4.10.1"
}
}
\ No newline at end of file
const test = require('tape');
const exercises = require('./exercises.js');
test('Testing isString method', t => {
t.equal(true, exercises.isString('Test'))
t.equal(true, exercises.isString(''))
t.equal(false, exercises.isString({}))
t.equal(false, exercises.isString([]))
t.equal(false, exercises.isString(12))
t.end()
})
<!DOCTYPE html> <!-- just to say we want to use html site -->
<html lang="en">
<!-- defines main language of website -->
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- width device width is to make usre that it adapts to mobile/different screen sizes -->
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<!-- to link the CSS file - we use link tag in the head -->
<title>Document</title> <!-- tittle of tab -->
</head>
<body>
</body>
</html>
<!-- head is for server and crawlers ; has meta data, SEO etc -->
<!-- search engines do not understand semantics so we need to use good practices, so that things are read as , e.g. if they see a button class (CSS) crawlers from search engines and disbaled user tools (screen readers) will know that is a "button", if button is made with div they will not know -->
<!-- div - main use for the is to split things; one interview question was to write a button, so thye see if you use a class (which you should) -->
<!-- p - is paragraph -->
<!-- span - different than div, bc it tkaes only the space it needs, can also be used to apply styles to specific words in a text -->
<!-- CSS RESET - copy paste it to my website to reset any browser specific styles -->
<!-- shoudl only have 2 types of clickable elements in website: anchor link (rediects to new page); and button -->
<!-- aside tag to put nav menus on the side of the page -->
<!-- hr - thematic break-->
<!-- form tag to submit information always need to wrap i tin this tag -->
<!-- google chrome - got to inspect element -- AUDIT -- gives us pointers to improve website -->
<!--CSS -->
<!--to add style we can add in a file in CSS, in a style tag in the html file (in the head), in the tags themselves; but best practice is to use CSS -->
<!-- in CSS order maters within each type (ID, class, tag), but there is a priority order between different categories: ID first, class second, tag third-->
<!-- display: inline, block and inline block - inline block allows to define margin and if we are applying it to a span tag, so we cna change the width and height a little -->
<!-- flex display is REALLY IMPORTANT-->
<!-- positions: STATIC(default), FIXED (relative to the viewport of the browser - ie always y=0, x=10px to the left), ABSOLUTE - relative to the body always, independent of parents - RELATIVE, changes it relative to the body OR the parent tag if the parent is not static (ie, has a class / a margin)-->
<!-- the best position is relative; for absolute or fixed elements, sometimes mobiles do not show them right while scrolling, bc these are outside the flow of a website-->
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment