-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1186a90
commit 090ed2b
Showing
52 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
BasicAlgorithmAndDataStructures/IterateThroughKeysOfAnObj.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const users = { | ||
Alan: { | ||
online: false | ||
}, | ||
Jeff: { | ||
online: true | ||
}, | ||
Sarah: { | ||
online: false | ||
} | ||
} | ||
|
||
function countOnline(usersObj) { | ||
|
||
// Only change code below this line | ||
let count = 0; | ||
for (let user in usersObj) { | ||
if (usersObj[user].online == true) { | ||
count++; | ||
} | ||
} | ||
return count; | ||
// Only change code above this line | ||
} | ||
|
||
console.log(countOnline(users)); |
28 changes: 28 additions & 0 deletions
28
BasicAlgorithmAndDataStructures/ModifyArrayStoredInObjs.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
let user = { | ||
name: 'Kenneth', | ||
age: 28, | ||
data: { | ||
username: 'kennethCodesAllDay', | ||
joinDate: 'March 26, 2016', | ||
organization: 'freeCodeCamp', | ||
friends: [ | ||
'Sam', | ||
'Kira', | ||
'Tomo' | ||
], | ||
location: { | ||
city: 'San Francisco', | ||
state: 'CA', | ||
country: 'USA' | ||
} | ||
} | ||
}; | ||
|
||
function addFriend(userObj, friend) { | ||
// Only change code below this line | ||
userObj.data.friends.push(friend); | ||
return userObj.data.friends; | ||
// Only change code above this line | ||
} | ||
|
||
console.log(addFriend(user, 'Pete')); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
let users = { | ||
Alan: { | ||
age: 27, | ||
online: false | ||
}, | ||
Jeff: { | ||
age: 32, | ||
online: true | ||
}, | ||
Sarah: { | ||
age: 48, | ||
online: false | ||
}, | ||
Ryan: { | ||
age: 19, | ||
online: true | ||
} | ||
}; | ||
|
||
function getArrayOfUsers(obj) { | ||
// Only change code below this line | ||
let Newarr = Object.keys(obj); | ||
return Newarr; | ||
// Only change code above this line | ||
} | ||
|
||
console.log(getArrayOfUsers(users)); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
function CompareForSort(first, second) { | ||
if (first == second) | ||
return 0; | ||
if (first < second) | ||
return -1; | ||
else | ||
return 1; | ||
} | ||
function getIndexToIns(arr, num) { | ||
arr.sort(CompareForSort); | ||
for (let i = 0; i < arr.length; i++) { | ||
if (arr[i] == num) { | ||
return i; | ||
} | ||
if (arr[i] > num) { | ||
return i; | ||
} | ||
|
||
} | ||
return arr.length; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function bouncer(arr) { | ||
let newarr = []; | ||
for (let i = 0; i < arr.length; i++) { | ||
if (arr[i]) { | ||
newarr.push(arr[i]); | ||
} | ||
} | ||
return newarr; | ||
} | ||
|
||
console.log(bouncer([7, "ate", "", false, 9])); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
function convertToF(celsius) { | ||
let fahrenheit = 9 / 5 * celsius + 32; | ||
return fahrenheit; | ||
} | ||
|
||
convertToF(30); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
function confirmEnding(str, target) { | ||
let regex = new RegExp(target + "$", "i"); | ||
return regex.test(str); | ||
} | ||
|
||
console.log(confirmEnding("Bastian", "n")); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function factorialize(num) { | ||
let res = 1; | ||
while (num >= 1) { | ||
res = res * num; | ||
num--; | ||
} | ||
return res; | ||
} | ||
|
||
factorialize(5); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
function findLongestWordLength(str) { | ||
let strArr = str.split(' '); | ||
console.log(strArr); | ||
let LongestString = 0; | ||
for (let index = 0; index < strArr.length; index++) { | ||
if (strArr[index].length > LongestString) { | ||
LongestString = strArr[index].length; | ||
} | ||
} | ||
return LongestString; | ||
} | ||
|
||
findLongestWordLength("The quick brown fox jumped over the lazy dog"); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function titleCase(str) { | ||
let strArr = str.split(' '); | ||
for (let index = 0; index < strArr.length; index++) { | ||
strArr[index] = strArr[index].toLowerCase(); | ||
strArr[index] = strArr[index].charAt(0).toUpperCase() + strArr[index].slice(1); | ||
} | ||
return strArr.join(' '); | ||
} | ||
|
||
console.log(titleCase("sHoRt AnD sToUt")); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
function repeatStringNumTimes(str, num) { | ||
if (num <= 0) { | ||
return ''; | ||
} | ||
let newStr = []; | ||
while (num >= 1) { | ||
newStr.push(str); | ||
num--; | ||
} | ||
return newStr.join(''); | ||
} | ||
|
||
console.log(repeatStringNumTimes("abc", 3)) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
function largestOfFour(arr) { | ||
let finalarr = []; | ||
for (let i = 0; i < arr.length; i++) { | ||
let largest = arr[i][0]; | ||
for (let arrIndex = 0; arrIndex < arr[i].length; arrIndex++) { | ||
if (arr[i][arrIndex] > largest) { | ||
largest = arr[i][arrIndex]; | ||
} | ||
} | ||
console.log(largest); | ||
finalarr.push(largest); | ||
|
||
} | ||
return finalarr; | ||
} | ||
|
||
console.log(largestOfFour([[17, 23, 25, 12], [25, 7, 34, 48], [4, -10, 18, 21], [-72, -3, -17, -10]])); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function reverseString(str) { | ||
let strArr = str.split(""); | ||
strArr = strArr.reverse(); | ||
str = strArr.join(''); | ||
return str; | ||
} | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function truncateString(str, num) { | ||
let Strarr = str.split(''); | ||
let resarr = Strarr.slice(0, num); | ||
if (num < Strarr.length) { | ||
resarr.push("..."); | ||
} | ||
return resarr.join(''); | ||
} | ||
|
||
console.log(truncateString("A-tisket a-tasket A green and yellow basket", 8)); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function booWho(bool) { | ||
return typeof (bool) == "boolean"; | ||
} | ||
|
||
booWho(null); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function frankenSplice(arr1, arr2, n) { | ||
let arr3 = arr2.slice(); | ||
for (let i = 0; i < arr1.length; i++) { | ||
arr3.splice(n + i, 0, arr1[i]); | ||
} | ||
return arr3; | ||
} | ||
console.log(frankenSplice([1, 2, 3], [4, 5], 1)); |