JAVASCRIPT: (Feel free to test me on concepts shown below even during my sleep)
Array of numbers and returns the sum of all the numbers in the array:
function sumArray(numbers) {
var sum = 0;
for (var i = 0; i < numbers.length; i++) {
sum += numbers[i];
}
return sum;
}
// Example usage:
var numbers = [1, 2, 3, 4, 5];
var sum = sumArray(numbers);
console.log(sum); // Output: 15
Function that takes a string and returns a reversed version of the string:
function reverseString(string) {
var reversedString = "";
for (var i = string.length - 1; i >= 0; i--) {
reversedString += string[i];
}
return reversedString;
}
// Example usage:
var string = "Hello, world!";
var reversedString = reverseString(string);
console.log(reversedString); // Output: "!dlrow ,olleH"
Takes a number and returns a Boolean value indicating whether the number is prime:
function swapObjectKeysAndValues(object) {
var newObject = {};
for (var key in object) {
newObject[object[key]] = key;
}
return newObject;
}
// Example usage:
var object = {
name: "John Doe",
age: 30,
occupation: "Software Engineer"
};
var newObject = swapObjectKeysAndValues(object);
console.log(newObject); // Output: { "Software Engineer": "occupation", "30": "age", "John Doe": "name" }
Function that takes a string and returns a new string with all the vowels removed:
function removeVowels(string) {
var vowels = ["a", "e", "i", "o", "u"];
var newString = "";
for (var i = 0; i < string.length; i++) {
if (!vowels.includes(string[i])) {
newString += string[i];
}
}
return newString;
}
// Example usage:
var string = "Hello, world!";
var newString = removeVowels(string);
console.log(newString); // Output: "Hll, wrld!"
Function that takes an object and returns a new object with all the keys and values swapped
function swapObjectKeysAndValues(object) {
var newObject = {};
for (var key in object) {
newObject[object[key]] = key;
}
return newObject;
}
// Example usage:
var object = {
name: "John Doe",
age: 30,
occupation: "Software Engineer"
};
var newObject = swapObjectKeysAndValues(object);
console.log(newObject); // Output: { "Software Engineer": "occupation", "30": "age", "John Doe": "name" }
Notes for myself:
-> Javascript unlike HTML, CSS is almost like a programing language which allows for logic statements like if, else, etc.
-> So many use cases like Tablet, Mobile, Laptop,
-> Ionicframework.com - it has many frameworks built in for mobile applications like sliders, buttons, alert, etc. It has Angular (for dynamism), VUE (for human Input), React(),
-> Browsers have entire javascript built into it. However, that's not the case with node js, angular js,
-> Javascript can dynamically modify any element on the webpage with an ID (it could be table, slider, header, etc) and later define that ID.
-> A good programmer is the one who takes care of the time-space complexity. Meaning, who makes the phone/computer least amount of efforts (least number of computations or least expensive computations) is a better programmer.
-> Python is an interpreted language.
-> Primary Domain -> VisualStudio.com and subdomain code.visualstudio.com
-> By default the web server looks for index.html file or home.html file when we try to open a website.
->Github to code collaboration environment.
-> Virtual environment is a localized environment is not portable and it requires an operating system.
-> Docker is portable and does not require an operating system to work and for its resources.