Skip to content

Update array_strings_2.js #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion array_strings_2.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ Output: 31
Input: 895796
Output: 695798


function revDigits(num){
var digits = num.toString().split('');
var arrDigits = digits.map(Number)
let n=arrDigits[0];
arrDigits[0]=arrDigits[arrDigits.length-1];
arrDigits[arrDigits.length-1]=n;
let k=arrDigits.join('');
return k;
}
---------------

2. Write down a function which will receive 2 arrays of numbers merge them and return second biggest element of merged array.
Expand All @@ -14,7 +24,14 @@ Output: 7

Input [1, 4]; [3, 6]
Output: 4


const arr_1=[];
const arr_2=[];
function bigNumber_2(arr_1,arr_2){
arr_1=arr_1.concat(arr_2);
arr_1.sort((a,b)=>a-b);
return arr_1[arr_1.length-2];
}
---------------

3. Write down a function which will receive an array of numbers and remove duplicates from it (using Set)
Expand All @@ -24,6 +41,10 @@ Output: [1, 3, 5, 2, 6]
Input: [1, 1, 1, 3]
Output: [1, 3]

function remDoubleNum(arr){
const del = [... new Set(arr)];
return del;
}
---------------

4. Create an implementation of the rotational cipher, also sometimes called the Caesar cipher.
Expand All @@ -37,6 +58,18 @@ The letter is shifted for as many values as the value of the key.

Input: Hello world, 7
Output Olssv dvysk


function caesarShift(text, shift) {
var result = "";
for (var i = 0; i < text.length; i++) {
var c = text.charCodeAt(i);
if (65 <= code && code <= 90) result += String.fromCharCode((code - 65 + shift) % 26 + 65);
else if (97 <= code && code <= 122) result += String.fromCharCode((code - 97 + shift) % 26 + 97);
else result += text.charAt(i);
}
return result;
}

2. Decode function
Input: Olssv dvysk, 7
Expand All @@ -51,6 +84,12 @@ The letter is shifted for as many values as the value of the key.
Example: if current time is 23:59:45 function should print 15
Example: if current time is 23:50:45 function should print 555


function GetWeekDays (y,m,d) {
var date= new Date(y,m,d);
var days=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturdy"];
return days[date.getDay()];
}
---------------

6. Write down a function which will print week day based on provided day.
Expand All @@ -59,3 +98,16 @@ Output: "Monday"

Input: "2014/09/12"
Output: "Friday"

function myFunction() {
var d = new Date();
let sum=Number;
let k=d.getHours();
if(k > 23) {
return "Too late";
}
else {
sum= (23-d.getHours())*3600 + (59-d.getMinutes())*60 +(60-d.getSeconds());
}
return sum;
}