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
// validate input array elements | |
function isIntegerArray (input) { | |
// if an array | |
if (Array.isArray(input)) { | |
// if empty array | |
if (input.length < 1) return false | |
// iterate through each element and return false if one of them happens to be not an integer | |
for (let i = 0; i < input.length; i++) { | |
if (Number.isInteger(input[i])) continue |
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
// validate input array elements | |
function isIntegerArray (input) { | |
// if an array | |
if (Array.isArray(input)) { | |
// if empty array | |
if (input.length < 1) return false | |
// iterate through each element and return false if one of them happens to be not an integer | |
for (let i = 0; i < input.length; i++) { | |
if (Number.isInteger(input[i])) continue |
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
// validate input array elements | |
function isIntegerArray (input) { | |
// if an array | |
if (Array.isArray(input)) { | |
// if empty array | |
if (input.length < 1) return false | |
// iterate through each element and return false if one of them happens to be not an integer | |
for (let i = 0; i < input.length; i++) { | |
if (Number.isInteger(input[i])) continue |
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
// validate input array elements | |
function isIntegerArray (input) { | |
// if an array | |
if (Array.isArray(input)) { | |
// if empty array | |
if (input.length < 1) return false | |
// iterate through each element and return false if one of them happens to be not an integer | |
for (let i = 0; i < input.length; i++) { | |
if (Number.isInteger(input[i])) continue |
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
function swapWithoutThirdVariable({ firstNo, secondNo }) { | |
// if either of two input numbers don't pass as integers, return error | |
if (!Number.isInteger(firstNo) || !Number.isInteger(secondNo)) { | |
return 'Please input two integers for both "firstNo" and "secondNo"' | |
} | |
// first number is sum of two numbers | |
firstNo = firstNo + secondNo | |
// get first number again afer subtracting the second number from sum (firstNo) |
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
function firstUniqueCharacter(text) { | |
// split string into single characters | |
let characters = String(text).split("") | |
if (characters.length < 1) return 'Please input a non-empty string' | |
// iterate through array, comparing each character to the rest | |
// if found no match for a certain character after comparing to all other characters, return character at the end of first such iteration |
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
function countCharOccurances (text, character) { | |
// convert input to string and split the string into an array of charaters | |
let chars = String(text).split("") | |
// if doesn't include, return 0 | |
if (!chars.includes(String(character))) { | |
return 0 | |
} else { | |
let count = 0 | |
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
//test cases | |
let tests = [ | |
{ | |
input: 3, | |
result: 'Please input an array of integers.' | |
}, | |
{ | |
input: '[]', | |
result: 'Please input an array of integers.' | |
}, |
NewerOlder