Skip to content

Instantly share code, notes, and snippets.

@LitHaxor
Created June 14, 2023 16:56
Show Gist options
  • Select an option

  • Save LitHaxor/69a03fdd152a94874dcb0716eed54c0d to your computer and use it in GitHub Desktop.

Select an option

Save LitHaxor/69a03fdd152a94874dcb0716eed54c0d to your computer and use it in GitHub Desktop.
// Problem 1
// const nums = [1, 2, 3, 4];
const problem1 = (nums) => {
const result = [];
for (let i = 0; i < nums.length; i++) {
result.push();
}
return result;
};
console.log(problem1([1, 2, 3, 4]));
// console.log(problem1([1, 2, 3, 4]) == [1, 3, 6, 10]);
// Problem 2
function reverseString(str) {
str = str.split("");
let startLen = 0;
let endLen = str.length - 1;
let specialChars = []
let specialCharPositions = []
for (let i = 0; i < str.length; i++) {
if ((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z')) {
continue;
} else {
specialChars.push(str[i])
specialCharPositions.push(str[i])
}
}
while (startLen < endLen) {
let temp = str[startLen];
str[startLen] = str[endLen];
str[endLen] = temp;
startLen++;
endLen--;
}
return str.join("");
}
console.log(reverseString("a-bC-dEf-ghIj"));
// problem 3
function problem3(num) {
const sp = `${num}`.split('')
const nums = []
for (let i = 0; i < sp.length; i++) {
nums.push(Number(sp[i]))
}
return nums.reduce((a,b)=> a+b)
}
console.log(problem3(38))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment