From 8eb52d30e9f032eae40026c8939db6f034d22aa1 Mon Sep 17 00:00:00 2001 From: KarinAnt <56351086+KarinAnt@users.noreply.github.com> Date: Mon, 14 Oct 2019 18:52:48 +0400 Subject: [PATCH 1/2] Update array_strings_2.js No End --- array_strings_2.js | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/array_strings_2.js b/array_strings_2.js index 4873142..d4bf3f9 100644 --- a/array_strings_2.js +++ b/array_strings_2.js @@ -4,7 +4,15 @@ Output: 31 Input: 895796 Output: 695798 - + function reversNumber(a){ + let arr = String(a).split(""); + for(let i = 0; i< arr.length/2; i++){ + let b = arr[i]; + arr[i]=arr[arr.length - 1 -i]; + arr[arr.length - 1 -i] = b; + } + return Number(arr.join("")); +} --------------- 2. Write down a function which will receive 2 arrays of numbers merge them and return second biggest element of merged array. @@ -14,7 +22,14 @@ Output: 7 Input [1, 4]; [3, 6] Output: 4 - + function twoArraySecondBiggest(arr1, arr2){ + var arr = []; + arr = arr.concat(arr1, arr2); + let max = arr.reduce((p,v)=>((p(v((p Date: Tue, 15 Oct 2019 14:13:48 +0400 Subject: [PATCH 2/2] Update array_strings_2.js End exercises --- array_strings_2.js | 64 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/array_strings_2.js b/array_strings_2.js index d4bf3f9..90eec20 100644 --- a/array_strings_2.js +++ b/array_strings_2.js @@ -55,14 +55,74 @@ The letter is shifted for as many values as the value of the key. Input: Hello world, 7 Output Olssv dvysk - +function caesarCipherEncode(str, n){ + var a = []; + for(let i = 0; i < str.length; i++){ + if(str.charCodeAt(i)>96 && str.charCodeAt(i)<123){ + if(str.charCodeAt(i) + n > 122){ + a += String.fromCharCode(str.charCodeAt(i) + n - 122 + 96); + }else{ + a += String.fromCharCode(str.charCodeAt(i) + n); + } + }else if(str.charCodeAt(i)>64 && str.charCodeAt(i)<91){ + if(str.charCodeAt(i) + n > 90){ + a += String.fromCharCode(str.charCodeAt(i) + n - 90 + 64); + }else{ + a += String.fromCharCode(str.charCodeAt(i) + n); + } + }else{ + a += str[i]; + } + } + return a; +} 2. Decode function Input: Olssv dvysk, 7 Output: Hello world Input: bcd, 1 Output: abc - + function caesarCipherDecode(str, n){ + var a = []; + for(let i = 0; i < str.length; i++){ + if(str.charCodeAt(i)>96 && str.charCodeAt(i)<123){ + if(str.charCodeAt(i) - n < 97){ + a += String.fromCharCode(str.charCodeAt(i) - n + 122 - 96); + }else{ + a += String.fromCharCode(str.charCodeAt(i) - n); + } + }else if(str.charCodeAt(i)>64 && str.charCodeAt(i)<91){ + if(str.charCodeAt(i) - n < 65){ + a += String.fromCharCode(str.charCodeAt(i) - n + 91 - 65); + }else{ + a += String.fromCharCode(str.charCodeAt(i) - n); + } + }else{ + a += str[i]; + } + } + return a; +}function caesarCipherDecode(str, n){ + var a = []; + for(let i = 0; i < str.length; i++){ + if(str.charCodeAt(i)>96 && str.charCodeAt(i)<123){ + if(str.charCodeAt(i) - n < 97){ + a += String.fromCharCode(str.charCodeAt(i) - n + 122 - 96); + }else{ + a += String.fromCharCode(str.charCodeAt(i) - n); + } + }else if(str.charCodeAt(i)>64 && str.charCodeAt(i)<91){ + if(str.charCodeAt(i) - n < 65){ + a += String.fromCharCode(str.charCodeAt(i) - n + 91 - 65); + }else{ + a += String.fromCharCode(str.charCodeAt(i) - n); + } + }else{ + a += str[i]; + } + } + return a; +} --------------- 5. Write down a function which will print the number of the rest seconds until the current day's end.