diff --git a/array_strings_2.js b/array_strings_2.js index 4873142..90eec20 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((p96 && 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. 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 secondsDayEnd(){ + var date = new Date(); + let h = date.getHours(); + let m = date.getMinutes(); + let s = date.getSeconds(); + h = (23 - h) * 3600; + m = (59 - m) * 60; + s = 60 - s; + return h + m + s; +} --------------- 6. Write down a function which will print week day based on provided day. @@ -59,3 +146,9 @@ Output: "Monday" Input: "2014/09/12" Output: "Friday" +function dateToDay(str){ + const days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]; + var arr = str.split('/'); + var date = new Date(arr[0],arr[1] - 1, arr[2]); + return days[date.getDay()]; +}