Methods
everyOtherLetter(str) → {str}
Returns a new string with every other letter.
Parameters:
| Name | Type | Description |
|---|---|---|
str |
string | a string |
- Source:
Returns:
-
ex: everyOtherLetter("mississippi") //=> "msispi"
- Type
- str
howManyTargets(arr, target) → {number}
Returns the number of times the target is in the array
Parameters:
| Name | Type | Description |
|---|---|---|
arr |
Array | array of elements |
target |
any | target to find in array |
- Source:
Returns:
- amount of times the target was included
ex: howManyTargets([1, 2, 3, 2, 1, 1], 1) //=> 3
- Type
- number
isDivisibleBy9(num) → {boolean}
Returns if a number is divisible by 9.
Parameters:
| Name | Type | Description |
|---|---|---|
num |
number | a number |
- Source:
Returns:
- is the number divisible by 9
ex: isDivisibleBy9(27) //=> true
ex: isDivisibleBy9(16) //=> false
- Type
- boolean
letterCount(str) → {Object}
Return a frequency map of each letter in a string, ignores spaces.
Parameters:
| Name | Type | Description |
|---|---|---|
str |
string | a string |
- Source:
Returns:
- the characters and their frequency
ex: letterCount("hello world") //=> {h: 1, e: 1, l: 3, o: 2, w: 1, r: 1, d: 1}
- Type
- Object
longestWord(words) → {string}
Returns the longest word in the array.
Ties should go to the earlier word
Parameters:
| Name | Type | Description |
|---|---|---|
words |
Array.<string> | an array containing words |
- Source:
Returns:
- longest word
ex: longestWord(["cat", "bird", "hello", "corey", "do"])
returns "hello"
- Type
- string
numberIncludes0(num) → {boolean}
Return if a given number includes 0.
Parameters:
| Name | Type | Description |
|---|---|---|
num |
number | a number |
- Source:
Returns:
- is zero in the number
ex: numberIncludes0(1023) //=> true
ex: numberIncludes0(123) //=> false
- Type
- boolean
onlyStringsGreaterThanOrEqualTo5(words) → {Array.<string>}
Returns an array of words that have 5 or more letters.
Parameters:
| Name | Type | Description |
|---|---|---|
words |
Array.<string> | an array containing words |
Returns:
- words with 5 or more letters
ex: onlyStringsGreaterThanOrEqualTo5(["cat", "hello", "corey", "dog"])
returns ["hello", "corey"]
- Type
- Array.<string>
productOfOddNumbers(nums) → {number}
Return the product of all odd numbers in an array.
Parameters:
| Name | Type | Description |
|---|---|---|
nums |
Array.<number> | an array containing numbers |
- Source:
Returns:
- product of all the odd numbers
ex: productOfOddNumbers([1, 2, 3, 4, 5])
returns 15
- Type
- number
sortPeopleByAge(people) → {Array.<Object>}
Takes in an array of people and sorts them by age
Parameters:
| Name | Type | Description |
|---|---|---|
people |
Array.<Object> | an array containing people objects |
- Source:
Returns:
- a sorted array
ex: sortPeopleByAge([
{ name: "Corey", age: 100 },
{ name: "Sam", age: 18 },
{ name: "Sparky", age: 500 },
{ name: "Peter", age: 50 },
])
returns [
{ name: "Sam", age: 18 },
{ name: "Peter", age: 50 },
{ name: "Corey", age: 100 },
{ name: "Sparky", age: 500 },
]
- Type
- Array.<Object>
sumOfValuesOfObject(obj) → {number}
Takes in an object and returns the sum of all values
Parameters:
| Name | Type | Description |
|---|---|---|
obj |
Object | an object with key value pairs |
- Source:
Returns:
- sum of all values
ex: sumOfValuesOfObject({corey: 5, sam: 10, peter: 3, sparky: 9})
returns 27
- Type
- number
thirdLargest(nums) → {number}
Return the third largest number. Cannot use sort.
Parameters:
| Name | Type | Description |
|---|---|---|
nums |
Array.<number> | an array containing numbers |
- Source:
Returns:
- third largest number
ex: thirdLargest([12, 3, 8, 2, 1, 14])
returns 8
- Type
- number