Created
June 14, 2023 16:56
-
-
Save LitHaxor/69a03fdd152a94874dcb0716eed54c0d to your computer and use it in GitHub Desktop.
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
| // 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