From ac505480189b3ce57e2d896dcea407a8fd1c09c9 Mon Sep 17 00:00:00 2001 From: SzymonHarajda <31370918+SzymonHarajda@users.noreply.github.com> Date: Mon, 27 Nov 2023 10:52:36 +0100 Subject: [PATCH 1/2] My solution --- solution_1.js | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ solution_2.js | 11 ++++++++++ 2 files changed, 67 insertions(+) create mode 100644 solution_1.js create mode 100644 solution_2.js diff --git a/solution_1.js b/solution_1.js new file mode 100644 index 0000000..9f03b7e --- /dev/null +++ b/solution_1.js @@ -0,0 +1,56 @@ +const arrToSort=[1,2,4,591,392,391,2,5,10,2,1,1,1,20,20]; + +const cleanTheRoom = (arr)=>{ + let sorted = arr.toSorted((a,b)=> a-b); + for(let i =0 ;i{ + let grup=[]; + let count=1; + for(let i = 0;i1&& i===0){ + i+=count; + grup.push([arr.toSpliced(i,arr.length)]); + i--; + count = 1; + } else if(count>1&& i>3){ + i+=count; + let subArr=arr.toSpliced(i,arr.length).toReversed(); + grup.push([subArr.toSpliced(count,subArr.length)]); + subArr=[]; + i--; + count = 1; + } + else{ + grup.push(arr[i]); + } + } + console.log(grup); +} + +const grupByType = (arr)=>{ + let mainArr=[]; + let stringArr=[]; + let numArr=[]; + for(let i =0 ;i{ + let sum=0; + let newArray=[]; + for(let i=0;i Date: Mon, 27 Nov 2023 10:54:34 +0100 Subject: [PATCH 2/2] solution_3 --- solution_3.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 solution_3.js diff --git a/solution_3.js b/solution_3.js new file mode 100644 index 0000000..754e43f --- /dev/null +++ b/solution_3.js @@ -0,0 +1,33 @@ +const rgb2hex=(array)=> { + var result = ""; + array.map(component => { + //changes rgb to hex component + var rgb = Number(component).toString(16); + //adds padding to components with length 1 + rgb = rgb.length == 1 ? "0" + rgb : rgb; + result += rgb; + }) + return '#' + result +} + +function hex2rgb(value) { + //finds red, green and blue components and writes them to array + var result = [value.slice(0,2), value.slice(2,4), value.slice(4)]; + //changes hex to rgb + result = result.map(component => parseInt(component, 16)) + return 'RGB ' + result.toString(); +} + +//function that recognises hex and rgb format +const convertHexRgb = (value)=> { + if (value.includes(",")) { + var array = value.split(","); + return rgb2hex(array); + + } else { + return hex2rgb(value); + + } +} + +convertHexRgb('FF0000'); \ No newline at end of file