Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
465f682
week-1-project/app.js file completed
Mert1980 Oct 30, 2019
c8007ae
week1 and week2 project files updated
Mert1980 Nov 4, 2019
798b1d1
week1 explicit coercion exercises completed
Mert1980 Nov 4, 2019
bfc0c82
completed early return pattern exercises
Mert1980 Nov 5, 2019
bd99a0c
week1 array exercises completed
Mert1980 Nov 5, 2019
0c3635a
week1 avoiding side effects exercises completed
Mert1980 Nov 5, 2019
db30042
week1 function to objects exercises completed
Mert1980 Nov 5, 2019
d20d927
Update README.md
Mert1980 Nov 5, 2019
6b15cb9
Update README.md
Mert1980 Nov 5, 2019
6b78a6c
Update README.md
Mert1980 Nov 5, 2019
103d076
Update README.md
Mert1980 Nov 5, 2019
42e2823
week2 and week3 files updated
Mert1980 Nov 5, 2019
f09803b
week2 practice problems object.js completed
Mert1980 Nov 6, 2019
eee2861
Update README.md
Mert1980 Nov 6, 2019
03cd3db
update on app.js and using-objects.js files
Mert1980 Nov 7, 2019
d85a203
Merge remote-tracking branch 'origin/master'
Mert1980 Nov 7, 2019
1607bb6
updated week-2 project files
Mert1980 Nov 7, 2019
aea62fe
updated app.js and index files
Mert1980 Nov 8, 2019
9ab7e9d
app.js and project-prep files are updated
Mert1980 Nov 8, 2019
faaa4db
some comments added, experimental codes removed
Mert1980 Nov 8, 2019
ae702a1
final version of app.js, findByValue method fixed
Mert1980 Nov 9, 2019
e8810a6
updated js2 files
Mert1980 Nov 10, 2019
f0eb94c
files changed
Mert1980 Nov 10, 2019
8f1ae7d
week3 practice problems completed
Mert1980 Nov 10, 2019
04b7cde
Update README.md
Mert1980 Nov 10, 2019
5c999b2
Update README.md
Mert1980 Nov 10, 2019
c81ccb9
updated practice exercises
Mert1980 Nov 11, 2019
e665b94
Merge remote-tracking branch 'origin/master'
Mert1980 Nov 11, 2019
35757ef
updated the solution of the last 2 exercises
Mert1980 Nov 11, 2019
322e58c
Update README.md
Mert1980 Nov 11, 2019
df15fc0
Update README.md
Mert1980 Nov 11, 2019
2e26885
Update README.md
Mert1980 Nov 11, 2019
ad9a11d
Update README.md
Mert1980 Nov 11, 2019
b6668c9
Update README.md
Mert1980 Nov 11, 2019
f2fd391
Update README.md
Mert1980 Nov 11, 2019
6197810
updated app.js
Mert1980 Nov 14, 2019
b22086a
Merge remote-tracking branch 'origin/master'
Mert1980 Nov 14, 2019
fa0dc17
updated app.js file
Mert1980 Nov 14, 2019
81c9ce3
updated app.js
Mert1980 Nov 14, 2019
0293b2e
updated app.js
Mert1980 Nov 15, 2019
e3bfcac
final version of app.js
Mert1980 Nov 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions week-1-project/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Week1 Practice Exercises Link
### Please follow the link below to open the practice exercises of Week1 project

<a href="https://mert1980.github.io/javascript-2/week-1-project/practice-problems/index.html">Practice Exercises Week1</a><br><br>

## Week 1 Project

The weekly projects in JS 2 will be making an even stronger distinction between your core application and the user interface. To help you with this transition there will be two assignment tables, one for the core app object and another for the user interface.
Expand Down
106 changes: 91 additions & 15 deletions week-1-project/app.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,119 @@
const object = {
numberyStrings: [],
NaNyStrings: [],
// evenStringsArr: [],
isNumberyString: function (param) {
// write me!
// return typeof param === 'string' && !isNaN(param);
return typeof param !== 'string' ? false :isNaN(param) ? false : true;
},
addString: function (param) {
if (null) return false; // write this early return condition

// write me! (using this.isNumberyString)
if (typeof param !== 'string') return false; // write this early return condition

else if (isNaN(param)) {this.NaNyStrings.push(param);}

else if (!isNaN(param)) {this.numberyStrings.push(param);}
return true;
},
allStrings: function () {
// write me!

if (this.NaNyStrings.length===0) return this.numberyStrings;
if(this.numberyStrings.length===0) return this.NaNyStrings;
return this.numberyStrings.concat(this.NaNyStrings);
},
evenStrings: function () {
// write me!
},

if ((this.NaNyStrings.length!==0) && (this.numberyStrings.length===0))
return this.numberyStrings;
else if ((this.NaNyStrings.length===0) && (this.numberyStrings.length!==0)){
function checkEven(num) {return num%2 === 0};
return this.numberyStrings.filter(checkEven);
}
else if ((this.NaNyStrings.length!==0) && (this.numberyStrings.length!==0)){
function checkEven(num) {return num%2 === 0};
return this.numberyStrings.filter(checkEven);
}
},
oddStrings: function () {
// write me!
if (this.NaNyStrings.length !== 0 && this.numberyStrings.length === 0)
return this.numberyStrings;
else if ((this.NaNyStrings.length===0) && (this.numberyStrings.length!==0)){
function checkOdd(num) {return num%2 !== 0};
return this.numberyStrings.filter(checkOdd);
}
else if ((this.NaNyStrings.length!==0) && (this.numberyStrings.length!==0)){
function checkOdd(num) {return num%2 !== 0};
return this.numberyStrings.filter(checkOdd);
}
},
negativeStrings: function () {
// write me!
if (this.NaNyStrings.length !== 0 && this.numberyStrings.length === 0)
return this.numberyStrings;
else if (this.NaNyStrings.length === 0 && this.numberyStrings.length !== 0){
function checkNegative(num) {return num < 0};
return this.numberyStrings.filter(checkNegative);
}
else if (this.NaNyStrings.length !== 0 && this.numberyStrings.length !== 0){
function checkNegative(num) {return num < 0};
return this.numberyStrings.filter(checkNegative);
}
},
positiveStrings: function () {
// write me!
if (this.NaNyStrings.length !== 0 && this.numberyStrings.length === 0)
return this.numberyStrings;
else if (this.NaNyStrings.length === 0 && this.numberyStrings.length !== 0){
function checkPozitive(num) {return num > 0};
return this.numberyStrings.filter(checkPozitive);
}
else if (this.NaNyStrings.length !== 0 && this.numberyStrings.length !== 0){
function checkPozitive(num) {return (num > 0 || num === "")};
return this.numberyStrings.filter(checkPozitive);
}
},
zeroStrings: function () {
// write me!

return this.numberyStrings.filter(num => num == 0);

// if (this.NaNyStrings.length !== 0 && this.numberyStrings.length === 0)
// return this.numberyStrings;
// else if (this.NaNyStrings.length === 0 && this.numberyStrings.length !== 0){
// function checkZero(num) {return (num == 0)}
// return this.numberyStrings.filter(checkZero);
// }else if (this.NaNyStrings.length !== 0 && this.numberyStrings.length !== 0){
// function checkZero(num) {return (num == 0)}
// return this.numberyStrings.filter(checkZero);
// }
},
numberyAsNumbers: function () {
// write me!
return this.numberyStrings.map(str => Number(str)); // in one line

// in multiple lines

/* if (this.NaNyStrings.length !== 0 && this.numberyStrings.length === 0)
return this.numberyStrings;
else if (this.NaNyStrings.length === 0 && this.numberyStrings.length !== 0){
function returnNumberyStrings(num) { return Number(num);}
return this.numberyStrings.map(returnNumberyStrings);}
else if (this.NaNyStrings.length !== 0 && this.numberyStrings.length !== 0){
function returnNumberyStrings(num) { return Number(num);}
return this.numberyStrings.map(returnNumberyStrings);} */
},
NaNyAsNumbers: function () {
// write me!
return this.NaNyStrings.map( str => Number(str));
},
sumOfNumbery: function () {
// write me! (using a Array.prototype.reduce())
if (this.NaNyStrings.length !== 0 && this.numberyStrings.length === 0 ) {
return 0;
}
function add(a, b) { return (a + b) };
return this.numberyAsNumbers().reduce(add);
},

sumOfNaNy: function () {
// write me!
if (this.NaNyStrings.length === 0 && this.numberyStrings.length !== 0) {
return NaN;
}
function add(a, b) { return (a + b) };
return this.NaNyAsNumbers().reduce(add);
},
};

Expand Down
53 changes: 30 additions & 23 deletions week-1-project/practice-problems/array-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ try {
{ name: 'fourth', args: [['hello'], ['world']], expected: ['hello', 'world'] },
];
function concatArrays(arr1, arr2) {
// write me!
return [...arr1, ...arr2];
}
concatArrays.display = true;
evaluate(concatArrays, concatArraysTests);
Expand All @@ -35,12 +35,13 @@ try {
{ name: 'seventh', args: ['Infinity'], expected: false },
{ name: 'eighth', args: ['infinity'], expected: true },
{ name: 'ninth', args: ['NaN'], expected: true },
{ name: 'tenth', args: [NaN], expected: null },
{ name: 'eleventh', args: [true], expected: null },
{ name: 'twelfth', args: [undefined], expected: null },
{ name: 'thirteenth', args: [null], expected: null },
{ name: 'tenth', args: [NaN], expected: true },
{ name: 'eleventh', args: [true], expected: false },
{ name: 'twelfth', args: [undefined], expected: true },
{ name: 'thirteenth', args: [null], expected: false },
];
function isNaNyString(arg) {
return isNaN(arg);
// write me!
// can you write this in one line? (isNaN will be helpful)
}
Expand All @@ -61,13 +62,15 @@ try {
{ name: 'first', args: [thingsToNumber1], expected: [1, 2] },
{ name: 'second', args: [thingsToNumber2], expected: [1, 10] },
{ name: 'third', args: [thingsToNumber3], expected: [2, 0] },
{ name: 'fourth', args: [thingsToNumber4], expected: null },
{ name: 'fifth', args: [[1, 2, 3]], expected: null },
{ name: 'fourth', args: [thingsToNumber4], expected: [1, 2] },
{ name: 'fifth', args: [[1, 2, 3]], expected: [1, 2, 3] },
{ name: 'sixth', args: [oddsToNumber], expected: [1, 3, 5] },
{ name: 'seventh', args: [evensToNumber], expected: [2, 4, 6] },
];
function returnAsNumbers(arr) { // return an array of nonNanny strings cast to Number
// write me!
let nonNaNyString = arr.filter(item => !(isNaNyString(item)));
let numberArray = nonNaNyString.map(item => Number(item));
return numberArray
// early return condition: array contains no numbery strings
// consider using a variation of your solution to isNaNyString (and .every)
};
Expand All @@ -89,10 +92,9 @@ try {
{ name: 'seventh', args: [numbersToSum3], expected: 2 },
];
function sumAll(arr) {
// write me!
// no early return, all the test cases are numbers!
// this solution will be very helpful for the next exercise
};
function add(a, b) { return (a + b) };
return arr.reduce(add);
};
sumAll.display = true;
evaluate(sumAll, sumAllTests);

Expand All @@ -109,22 +111,23 @@ try {
{ name: 'first', args: [sumNumberys1], expected: 3 },
{ name: 'second', args: [sumNumberys2], expected: 11 },
{ name: 'third', args: [sumNumberys3], expected: 2 },
{ name: 'fourth', args: [sumNumberys4], expected: null },
{ name: 'fifth', args: [[1, 2, 3]], expected: null },
{ name: 'fourth', args: [sumNumberys4], expected: 3 },
{ name: 'fifth', args: [[1, 2, 3]], expected: 6 },
{ name: 'sixth', args: [['1', '2', '3']], expected: 6 },
{ name: 'seventh', args: [oddsToSum], expected: 9 },
{ name: 'eighth', args: [evensToSum], expected: 12 },
];
function sumAllNumberys(arr) {
// write me!
let numberyArr = arr.filter(item => !isNaNyString(item))
.map(item => Number(item));
return sumAll(numberyArr);

// early return condition: array contains no numbery strings
};
sumAllNumberys.display = true;
evaluate(sumAllNumberys, sumAllNumberysTests);




const findEvensArray1 = ['.', '1', '2', ':'];
const findEvensArray2 = ['1', 'two', 'three', '10'];
const findEvensArray3 = ['one', '2', '', 'NaN'];
Expand All @@ -137,13 +140,15 @@ try {
{ name: 'first', args: [findEvensArray1], expected: ['2'] },
{ name: 'second', args: [findEvensArray2], expected: ['10'] },
{ name: 'third', args: [findEvensArray3], expected: ['2', ''] },
{ name: 'fourth', args: [findEvensArray4], expected: null },
{ name: 'fifth', args: [[1, 2, 3]], expected: null },
{ name: 'fourth', args: [findEvensArray4], expected: [2] },
{ name: 'fifth', args: [[1, 2, 3]], expected: [2] },
{ name: 'sixth', args: [oddsToNotFind], expected: [] },
{ name: 'seventh', args: [evensToFind], expected: ['2', '4', '6'] },
];
function findAllEvens(arr) {
// write me!
let numberyArr = arr.filter(item => !isNaNyString(item));
let evenArr = numberyArr.filter(item => item%2===0)
return evenArr;
// early return condition: array contains no numbery strings
};
findAllEvens.display = true;
Expand All @@ -163,13 +168,15 @@ try {
{ name: 'first', args: [findOddsArray1], expected: ['1'] },
{ name: 'second', args: [findOddsArray2], expected: ['1'] },
{ name: 'third', args: [findOddsArray3], expected: [] },
{ name: 'fourth', args: [findOddsArray4], expected: null },
{ name: 'fifth', args: [[1, 2, 3]], expected: null },
{ name: 'fourth', args: [findOddsArray4], expected: [1] },
{ name: 'fifth', args: [[1, 2, 3]], expected: [1, 3] },
{ name: 'sixth', args: [oddsToFind], expected: ['1', '3', '5'] },
{ name: 'seventh', args: [evensToNotFind], expected: [] },
];
function findAllOdds(arr) {
// write me!
let numberyArr = arr.filter(item => !isNaNyString(item));
let oddArr = numberyArr.filter(item => item%2!==0)
return oddArr;
// early return condition: array contains no numbery strings
};
findAllOdds.display = true;
Expand Down
41 changes: 21 additions & 20 deletions week-1-project/practice-problems/arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,23 @@ try {


function passTheAssertions1() {
; // declare and assign a1
; // declare and assign a2
let a1 = 2; // declare and assign a1
let a2 = a1; // declare and assign a2
console.assert(a1 === a2, 'a1 should strictly equal a2');

; // declare and assign b1
; // declare and assign b2
let b1 = 3; // declare and assign b1
let b2 = 4; // declare and assign b2
console.assert(b1 !== b2, 'b1 should not strictly equal b2');

// ---

; // write one line to pass the assertions
a1 = a2 = ["hi!"]; // write one line to pass the assertions
console.assert(a1[0] === a2[0], 'a1[0] should strictly equal a2[0]');
console.assert(a1[0] === 'hi!', 'a1.x should strictly equal "hi!"');

; // write two lines to pass the assertions
;
b1 = ['bye!']; // write two lines to pass the assertions
b2 = b1 = ['bye!'];

console.assert(b1[0] === b2[0], 'b1[0] should strictly equal b2[0]');
console.assert(b1[0] === 'bye!', 'b1.x should strictly equal "bye!"');
}
Expand All @@ -129,32 +130,32 @@ try {
const value1 = 5;
let reference1 = [];

; // write this line
let value2 = value1; // write this line
console.assert(value2 === value1, "value1 should strictly equal value2");

; // write this line
let reference2 = reference1; // write this line
console.assert(reference2 === reference1, "reference1 should strictly equal reference2");

value2 = value2 + 1; // write this line
console.assert(value1 !== null, "value1 should strictly equal ___");
console.assert(value1 !== value2, "value1 should strictly equal ___");

; // write this line
reference1 = reference2 = ['hi!']; // write this line
console.assert(reference1[0] === reference2[0], "references[0] should be strictly equal");
console.assert(reference1[0] === 'hi!', "reference1[0] should be strictly equal to 'hi!'");

; // write this line
reference1 === reference2; // write this line
console.assert(reference1 === reference2, "references should be strictly equal");

// remove the array from memory
; // write this line
; // write this line
reference1 = null; // write this line
reference2 = null; // write this line
}
evaluate(passTheAssertions2);


function passTheAssertions3() {
; // write this line
; // write this line
arr1 = ['A', 'B']; // write this line
arr2 = ['A', 'B']; // write this line
console.assert(arr1 !== arr2, 'the variables should not be strictly equal');
console.assert(arr1[1] === arr2[1], 'their first entries should be the same');
console.assert(arr1[1] === 'B', 'arr1[1]] should be "B"');
Expand All @@ -163,18 +164,18 @@ try {
console.assert(arr1[index] === arr2[index], 'arr1[index] should strictly equal arr2[index]');
console.assert(arr1[index] === 'A', 'arr1[index] should be "A"');

; // write this line
; // write this line
arr1 = ['A','B','1','2']; // write this line
arr2 = ['A','B','1']; // write this line
console.assert(arr1[arr2[2]] === 'B', 'arr2[2] should be "B"s index in arr1');
console.assert(arr1[arr2[2]] === arr2[arr1[2]], 'some tricky nested thing should be true');

; // write this line
let arr3 = arr2 = ['A','B','1']; // write this line
console.assert(arr1 !== arr2, 'arr1 should strictly equal arr2');
console.assert(arr3 !== arr1, 'arr3 should not strictly equal arr`');
console.assert(arr3 === arr2, 'arr3 should strictly equal arr2');
console.assert(arr3[index] === arr1[0], 'arr3[index] should strictly equal arr1[0]');

; // write this line
arr3 = ['A', 'B', 'A']; // write this line
console.assert(arr3[2] === arr2[index], 'arr3[2] should strictly equal arr2[index]');
}
evaluate(passTheAssertions3);
Expand Down
Loading