This file contains hidden or 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
| const conditionalSum = function(values, condition) { | |
| let total = 0; | |
| for (let val of values) { | |
| if (condition === "even") { | |
| val % 2 === 0 ? total += val : total += 0; | |
| } else if (condition === "odd") { | |
| val % 2 !== 0 ? total += val : total += 0; | |
| } else { | |
| continue; | |
| } |
This file contains hidden or 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
| const numberOfVowels = function(data) { | |
| let count = 0; | |
| for (let char of data) { | |
| switch(char) { | |
| case "a": | |
| count++; | |
| break; | |
| case "e": | |
| count++; | |
| break; |
This file contains hidden or 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
| const instructorWithLongestName = function(instructors) { | |
| let longestName = ""; | |
| for (let i of instructors) { | |
| i.name.length > longestName.length && (longestName = i.name); | |
| } | |
| return longestName; | |
| }; | |
| console.log(instructorWithLongestName([ | |
| {name: "Samuel", course: "iOS"}, |
This file contains hidden or 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
| const urlEncode = function(text) { | |
| let newURL = ""; | |
| for (let c = 0; c < text.length; c++) { | |
| text[c] === " " ? (c === 0 || c === text.length - 1) ? null : newURL += "%20" : newURL += text[c] | |
| } | |
| return newURL; | |
| }; | |
| console.log(urlEncode("Lighthouse Labs")); | |
| console.log(urlEncode(" Lighthouse Labs ")); |
This file contains hidden or 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
| const whereCanIPark = function (spots, vehicle) { | |
| let coords = null; | |
| let veh = []; | |
| if (vehicle === "regular") { | |
| veh = ["R"]; | |
| } else if (vehicle === "small") { | |
| veh = ["R", "S"]; | |
| } else if (vehicle === "motorcycle") { | |
| veh = ["R", "S", "M"]; | |
| } else { |
This file contains hidden or 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
| const checkAir = function (samples, threshold) { | |
| let countDirty = 0; | |
| for (let quality of samples) { | |
| quality === "dirty" ? countDirty++ : null; | |
| } | |
| let ratio = countDirty / samples.length; | |
| return (ratio > threshold ? "Polluted" : "Clean"); | |
| }; | |
| console.log(checkAir( |
This file contains hidden or 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
| const sumLargestNumbers = function(data) { | |
| let numOne = {index : 0, value : 0}; | |
| let numTwo = 0; | |
| for (let [i, num] of data.entries()) { | |
| num > numOne.value && (numOne.index = i) && (numOne.value = num); | |
| } | |
| data.splice(numOne.index, 1); | |
| for (let num of data) { | |
| num > numTwo && (numTwo = num); | |
| } |
This file contains hidden or 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
| const repeatNumbers = function(data) { | |
| const strRepeater = []; | |
| for (let pair of data) { | |
| let tempStr = ''; | |
| tempNum = pair[0].toString(); | |
| for (let i = 0; i < pair[1]; i++) { | |
| tempStr += tempNum; | |
| } | |
| strRepeater.push(tempStr); | |
| } |
This file contains hidden or 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
| const camelCase = function(input) { | |
| let tempString = ""; | |
| let capitalize = false; | |
| for (let char of input) { | |
| if (char === " ") { | |
| capitalize = true; | |
| continue; | |
| } else if (capitalize === true) { | |
| tempString += char.toUpperCase(); | |
| capitalize = false; |
This file contains hidden or 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
| const multiplicationTable = function(maxValue) { | |
| let numArray = []; | |
| for (i = 1; i <= maxValue; i++) { | |
| let rowArray = []; | |
| for (j = 1; j <= maxValue; j++) { | |
| rowArray.push(i * j); | |
| } | |
| numArray.push(rowArray); | |
| } | |
| let returnString = ''; |
OlderNewer