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
| var string = "password" | |
| function obfuscate(string) { | |
| var newString = ""; | |
| for (var i = 0; i < string.length; i++) { | |
| var char = string.charAt(i); | |
| if (char === "a") { | |
| newString += "4"; | |
| } else if (char === "e") { | |
| newString += "3"; |
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
| var conceptList = ["gists", "types", "operators", "iteration", "problem solving"]; | |
| function joinList(array) { | |
| var conceptListString = ""; | |
| for (var i = 0; i < array.length; i++) { | |
| conceptListString += array[i]; | |
| if (i < conceptList.length - 1) { | |
| conceptListString += ", "; | |
| } | |
| } | |
| console.log("Today I learned about " + conceptListString + ".") |
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
| var args = process.argv; | |
| console.log(Number(process.argv[2]) + (Number(process.argv[3]))); | |
| // First we give variable equal to process.argv (that will make any output into strings) | |
| // We use [2] and [3] because process.agrv itself comes with [0] , [1] array. | |
| // Oher option would be use process.argv.splice(2) and start the console.log(Number(process.argv[0])). |
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
| function whatToDoForLunch(hungry, availableTime) { | |
| if (hungry === false) { | |
| console.log("Get back to work"); | |
| } else if (hungry === true && availableTime < 20) { | |
| console.log("Pick something up and eat it in the lab"); | |
| } else if (hungry === true && availableTime > 20 && availableTime < 30) { | |
| console.log("Try a place nearby"); | |
| } else if (hungry === true && availableTime > 30) { | |
| console.log("Do you have that much time?"); | |
| } |
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
| var conditionalSum = function(values, condition) { | |
| var temp = 0; | |
| if (condition === "even") { | |
| for (var x = 0; x <= values.length; x++) { | |
| if (values[x] % 2 === 0) { | |
| temp += values[x]; | |
| } | |
| } | |
| } else if (condition === "odd") { | |
| for (var i = 0; i < values.length; i++) { |
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
| var repeatNumbers = function(data) { | |
| return data.map(([number, count]) => number.toString().repeat(count)).join(', ') | |
| } | |
| console.log(repeatNumbers([[1, 10]])); | |
| console.log(repeatNumbers([[1, 2], [2, 3]])); | |
| console.log(repeatNumbers([[10, 4], [34, 6], [92, 2]])); | |
| // using map function to create new array and including other functions like "toString" to make into string and "join" to combine the other arrays together witha a comma. |
NewerOlder