Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Basic-JavaScript
Submodule Basic-JavaScript added at e3cf82
6 changes: 6 additions & 0 deletions brainTeasers/waterJugs.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
You have a five-quart jug, a three-quart jug, and an unlimited supply of water (but no measuring cups). How would you come up with exactly four quarts of water? Note that the jugs are oddly shaped, such that filling up exactly "half" of the jug would be impossible.

1.Fill up the 5 quart jug with the 3 quart jug twice
2.You will have exactly 1 quart left on the second fill
3.Empty the 5 quart jug
4.Use the 1 quart left to measure the 4 quarts
and fill the 5 quart jug with 4 quarts
7 changes: 7 additions & 0 deletions callBackPractice/callBackPractice.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,38 @@ firstItem(foods, (firstItem) => {

getLength(foods, (length) => {
console.log(`The length of the array is ${length}.`);
cb(food.length);
});

// Write a function called last which passes the last item of the array into the callback

last(foods, (lastItem) => {
console.log(`The last item in the array is ${lastItem}.`);
cb(foods(foods.length -1));
});

// Write a function called sumNums that adds two numbers and passes the result to the callback


sumNums(5, 10, (sum) => {
const numSums = x + y;
cb(numSums);
console.log(`The sum is ${sum}.`);
});

// Write a function called multiplyNums that adds two numbers and passes the result to the callback

multiplyNums(5, 10, (product) => {
const numsMulti = x * y;
cb(numsMulti);
console.log(`The product is ${product}.`);
});

// Write a function called contains that checks if an item is present inside of the given array.
// Pass true to the callback if it is, otherwise pass false

contains(foods, 'ribeye', (result) => {
cb(foods.includes(item));
console.log(result ? 'ribeye is in the array' : 'ribeye is not in the array');
});

Expand Down
1 change: 1 addition & 0 deletions commonCharacters/commonCharacters.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
* Example: commonCharacters('acexivou', 'aegihobu') *
* Returns: 'aeiou'
*/

9 changes: 8 additions & 1 deletion constructors/constructors.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@
*
* This is how you would structure the game objects in an actual game
* application in Unity or another similar framework.
*/
*/
class NPC{
constructor(Humanoid, Animal, Plant) {
this.NPC= 'Charles';
this.strenght = strenght;
this.speed = speed;


28 changes: 26 additions & 2 deletions evenOccurences/evenOccurences.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,30 @@
* * console.log(onlyEven); // 4
* */

const evenOccurence = (arr) => {
//const evenOccurence = (arr) => {
// Your code here.
};
//};


// Prompt: Find the first item that occurs an even number of times in an array. Remember to handle multiple even-occurrence items and return the first one. Return null if there are no even-occurrence items.

function evenOccurrence (array)=> {
// Store counts
var storage = {};

// Store each value within the storage object to keep count
array.forEach(function(value, index) {
storage[value] = storage[value] + 1 || 1;
});

// loop through array to find first occurence of an even count
for (var i = 0; i < array.length; i++) {
var current = arr[i];

if (storage[current] % 2 === 0) {
return current;
}
}
// If no even occurrence found, return null
return null;
}
15 changes: 15 additions & 0 deletions forLoopTimeout/forLoopTimeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,25 @@
// The output should be 1, 2, 3, .... 10. Right now it just prints 11.
// I've been asked this three times in separate interviews.

<<<<<<< HEAD

for (var i = 0; i <=10; i++) {
=======
for (var i = 1; i <= 10; i++) {
>>>>>>> d1daab308de663dad2c7129e60c72bbb70519b4c
setTimeout(function() {
// From looking at the code you would assume it would print 1 - 10
// It doesn't. Why? How can you make it print 1 - 10.
console.log(i);
}, 0);
<<<<<<< HEAD
} // You have to include the loop witin a funtion to create a scope
for (var i = 0; i < =10; i++) {
(function (i) {
setTimeout(function () {
console.log(i)
}, 0);
})(i);
=======
>>>>>>> d1daab308de663dad2c7129e60c72bbb70519b4c
}
16 changes: 15 additions & 1 deletion isUnique/isUnique.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
/* Implement an algorithm to determine if a string has all unique characters.
* What if you cannot use additional data structures?
*/
*/
public static boolean isUniqueChars(String str) {
if (str.length() > 256) {
return false;
}
int checker = 0;
for (int i = 0; i < str.length(); i++) {
int val = str.charAt(i) - 'a';
if ((checker & (1 << val)) > 0) return false;
checker |= (1 << val);
}
return true;

//Test
console.log ( str ("abcds"))
4 changes: 3 additions & 1 deletion largestPrimePalindrome/largestPrimePalindrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
* Hint: it's 929
* You will first want to determine if the number is a palindrome and then determine if it is prime.
* A palindrome is a number that is the same forwards and backwards: 121, 323, 123454321, etc.
*/
*/


23 changes: 23 additions & 0 deletions longestString/longestString.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,26 @@
* Write a function that accepts an array of strings.
* Return the longest string in the array.
*/


// 1. identify test cases
// ['abc', 'a', 'b'] -> 'abc'
// ['abc', 'def'] -> 'def'
// [] -> null


/*function longestString strings
loop over the array of strings
do something in the loop
return longestString */

const longestString= (array) => {
let longest = 0;
for(let i=0; i<array.length-1; i++){
if (array[i].length > array[i+1].length ){
longest = array[i];
} else {
longest = array[i+1];
}
return longest; // than do something else
}
14 changes: 12 additions & 2 deletions removeDuplicates/removeDuplicates.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@
* So if you're using 'indexOf' 'sort' 'forEach' etc,
* you're more than likely using a for loop under the hood.
*/
var arr = [1, 1, 1, 2, 2, 3, 4, 5, 5, 6];
function newNum(arr){
let newArr = [];
for(var i = 0; i < arr.length; i++){
if(newArr.indexOf(arr[i]) == -1){
newArr.push(arr[i]);
}
}
return newArr;
}

const removeDuplicates = (arr) => {
console.log(newNum(arr));

//code here...
};
14 changes: 13 additions & 1 deletion reverseCase/reverseCase.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@
* Write a function that reverses the case of each letter in the strings that it receives.
* Example: 'Hello World' -> 'hELLO wORLD'
* Assume that each string will contain only spaces and letters.
*/
*/

const convertString = (str); => {
let s = '';
for (let i=0; i<str.length; i++) {
let n = str.charAt(i);
if (n.toLowerCase() === n){
s += n.toUpperCase();
} else {
s += n.toLowerCase();
}
}
return s;}