From 5465ac09178869dc64d7ffc7d1ea5fec2e4390d3 Mon Sep 17 00:00:00 2001 From: JT <57445142+JT-Singh@users.noreply.github.com> Date: Thu, 7 Sep 2023 13:42:10 +0100 Subject: [PATCH] Create Coding Singh My solution to Advance Java Exercise - Lecture 192. --- Coding Singh | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Coding Singh diff --git a/Coding Singh b/Coding Singh new file mode 100644 index 0000000..1568948 --- /dev/null +++ b/Coding Singh @@ -0,0 +1,73 @@ +//Question 1: Clean the room function: given an input of +// [1,2,4,591,392,391,2,5,10,2,1,1,1,20,20], make a function that +// organizes these into individual array that is ordered. For example +// answer(ArrayFromAbove) should return: [[1,1,1,1],[2,2,2], 4,5,10,[20,20], +// 391, 392,591]. + +function cleanRoom (array){ + let returnArray = []; + let subArray = []; + array.sort(function(a,b){return a-b}); + // debugger; + subArray.push(array[0]) + for (let i=1; i{return a === sum-element}) === "number"){ + returnArray.push(element,sum-element); + break; + } + } + return returnArray; +} + +// Question 3: Write a function that converts HEX to RGB. Then Make that function +// auto-dect the formats so that if you enter HEX color format it returns RGB and +// if you enter RGB color format it returns HEX. + +function componentToHex(c) { + var hex = c.toString(16); + return hex.length == 1 ? "0" + hex : hex; +} + +function rgbHexToggle(input){ + if (typeof input === "string"){ + return "R: "+parseInt(input.slice(1,3),16)+", G: "+parseInt(input.slice(3,5),16)+", B: "+parseInt(input.slice(5,),16) + } else { + return "#" + componentToHex(input[0]) + componentToHex(input[1]) + componentToHex(input[2]); + } + +}