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
150 changes: 150 additions & 0 deletions practiceQuestions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/**
* Returns a new string with every other letter.
* @param {string} str - a string
* @returns {str} -
*
* ex: everyOddCharacter("mississippi") //=> "issip"
*
*/

function everyOddCharacter(str) {}



/**
* Returns the characters from str that are found in targets array
* @param {string} str - string input
* @param {string[]} target - targets to find in string
* @returns {string} - amount of times the target was included
*
* ex: retieveTargets("hello world", ["h", "l", "o"] ) //=> "hllool"
*
*/

function retieveTargets(str, targets) {}



/**
* Returns true if every number is an odd number .
* @param {arr} nums - an array of numbers
* @returns {boolean} - is every number is an odd number
*
* ex: isOddNumbers([27, 17, 21, 51]) //=> true
* ex: isOddNumbers([1, 37, 5, 2]) //=> false
*
*/

function isOddNumbers(nums) {}


/**
* Return an array of letters that match the frequency value of that letter
* @param {Object} obj- the characters and their frequency
* @returns {Object} -
*
* ex: frequencyPrint({h: 1, e: 1, l: 2, o: 1}) //=> "hello"
*
*/

function frequencyPrint(obj) {}


/**
* Returns the longest word in the object.
* Ties should go to the earlier word
* @param {object} petNames - an object containing words
* @returns {string} - longest word
*
* ex: longestPetName({cat:"Tommy", bird:"Sunny", dog:"Sunshine", rat:"tiki"})
* returns "Sunshine"
*/

function longestPetName(petNames) {}


/**
* Return a number without zeros.
* @param {number} num - a number
* @returns {number || null} - a number without zeros
*
* ex: remove0(1023) //=> 123
* ex: remove0(0000000) //=> null
*
*/

function remove0(num) {}


/**
* Returns an array of words that includes a target character.
* @param {string[]} words - an array containing words
* @param {string} letter - a letter target
* @returns {string[]} - words that include target letter
*
* ex: onlyStringsThatContainTheTargetLetter(["cat", "hello", "corey", "dog", "hiccups"], "c")
* returns ["cat", "corey", "hiccups"]
*/

function onlyStringsThatContainTheTargetLetter(words, target) {}


/**
* Return the product of all even numbers in an array.
* @param {number[]} nums - an array containing numbers
* @returns {number} - product of all the odd numbers
*
* ex: productOfOddNumbers([1, 2, 3, 4, 5, 6])
* returns 48
*/

function productOfEvenNumbers(nums) {}

/**
* Takes in an object and returns the sum of all values
* @param {Object} obj - an object with key value pairs
* @returns {number} - sum of all values
*
* ex: sumOfValuesOfObject({corey: 5, sam: 10, peter: 3, sparky: 9, key: 10})
* returns 27
*/

function sumOfValuesOfObject(obj) {}


/**
* Return the third smallest number. Cannot use sort.
* @param {number[]} nums - an array containing numbers
* @returns {number} - third smallest number
*
* ex: thirdSmallest([12, 3, 8, 2, 1, 14])
* returns 3
*/

function thirdLargest(nums) {}


/**
* Takes in an array of cars and sorts them by year from newest to oldest
* @param {Object[]} people - an array containing car objects
* @returns {Object[]} - a sorted array
*
* ex: sortCarByYear([
{ car: "BMW", year: 2001 },
{ car: "Tesla", year: 2021 },
{ car: "Toyota", year: 1995 },
{ car: "Ford", year: 2020 },
])

/** returns [
{ car: "Tesla", year: 2021 },
{ car: "Ford", year: 2020 },
{ car: "BMW", year: 2005 },
{ car: "Toyota", year: 1995 },
]
*/

function sortCarByYear(peoples) {}



9 changes: 8 additions & 1 deletion problems/everyOtherLetter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
*
*/

function everyOtherLetter() {}
function everyOtherLetter(str) {
let newStr = ""
for(i = 0; i < str.length; i+=2) {
newStr += str[i]
}
return newStr
}


module.exports = everyOtherLetter;
10 changes: 9 additions & 1 deletion problems/howManyTargets.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
*
*/

function howManyTargets() {}
function howManyTargets(arr, target) {
let count = 0
arr.forEach((el) => {
if(el === target) {
count++
}
})
return count
}

module.exports = howManyTargets;
7 changes: 6 additions & 1 deletion problems/isDivisibleBy9.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
*
*/

function isDivisibleBy9() {}
function isDivisibleBy9(num) {
if(num % 9 === 0) {
return true
}
return false
}

module.exports = isDivisibleBy9;
17 changes: 16 additions & 1 deletion problems/letterCount.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@
*
*/

function letterCount() {}
function letterCount(str) {
let arr = str.split(" ")
let str1 = arr.join("")
let obj = {}
for(i = 0; i < str1.length; i++) {
let el = str1[i].toLowerCase()
if(obj[el]) {

obj[el] +=1

} else {
obj[el] = 1
}
}
return obj
}

module.exports = letterCount;
13 changes: 12 additions & 1 deletion problems/longestWord.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@
* returns "hello"
*/

function longestWord() {}
function longestWord(words) {
let longest = words[0]
for(i = 0; i < words.length; i++) {
let el = words[i]
if(el.length > longest.length) {
longest = el
} else if(el.length === longest.length) {
longest
}
}
return longest
}

module.exports = longestWord;
12 changes: 11 additions & 1 deletion problems/numberIncludes0.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
*
*/

function numberIncludes0() {}
function numberIncludes0(num) {
let newStr = '' + num
let newArr = newStr.split("")
for(i = 0; i < newArr.length; i++) {
if(newArr[i] === "0") {
return true
} else {
}
}
return false
}

module.exports = numberIncludes0;
6 changes: 5 additions & 1 deletion problems/onlyStringsGreaterThanOrEqualTo5.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
* returns ["hello", "corey"]
*/

function onlyStringsGreaterThanOrEqualTo5() {}
function onlyStringsGreaterThanOrEqualTo5(words) {
return words.filter((word) => {
return word.length >= 5
})
}

module.exports = onlyStringsGreaterThanOrEqualTo5;
20 changes: 16 additions & 4 deletions problems/productOfOddNumbers.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
/**
* Return the product of all odd numbers in an array.
* Return the product of all odd numbers in an array.
* @param {number[]} nums - an array containing numbers
* @returns {number} - product of all the odd numbers
*
*
* ex: productOfOddNumbers([1, 2, 3, 4, 5])
* returns 15
*/

function productOfOddNumbers() {}
function productOfOddNumbers(nums) {
let product = 1;

let numOfOdds = nums.filter((num) => num % 2===1 )
if(numOfOdds.length === 0) {
return 0
} else {
numOfOdds.forEach((num) =>{
product *= num
})
}
return product
}

module.exports = productOfOddNumbers
module.exports = productOfOddNumbers;
6 changes: 5 additions & 1 deletion problems/sortPeopleByAge.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
]
*/

function sortPeopleByAge() {}
function sortPeopleByAge(people) {
return people.sort((a, b) => {
return a.age - b.age
})
}

module.exports = sortPeopleByAge;
9 changes: 8 additions & 1 deletion problems/sumOfValuesOfObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
*/


function sumOfValuesOfObject(){}
function sumOfValuesOfObject(obj){
let sum = 0
let objValues = Object.values(obj)
objValues.forEach((el) => {
sum += el
})
return sum
}

module.exports = sumOfValuesOfObject;
22 changes: 21 additions & 1 deletion problems/thirdLargest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@
* returns 8
*/

function thirdLargest() {}
function thirdLargest(nums) {
let thirdLarge = -Infinity
let largest = -Infinity
let secondLargest = -Infinity
for(let i = 0; i < nums.length; i++) {
let el = nums[i]
if(nums.length < 3) {
return null
} else if(el > largest) {
thirdLarge = secondLargest
secondLargest = largest
largest = el
} else if(el > secondLargest) {
thirdLarge = secondLargest
secondLargest = el
} else if(el > thirdLarge) {
thirdLarge = el
}
}
return thirdLarge
}

module.exports = thirdLargest