Skip to content

Instantly share code, notes, and snippets.

View cormac0108's full-sized avatar
🌍
Open To Work

Cormac Donohoe cormac0108

🌍
Open To Work
  • Ireland
View GitHub Profile
@cormac0108
cormac0108 / Two-Sum-Challenge.js
Created July 20, 2020 23:21
Question 2: Write a javascript function that takes an array of numbers and a target number. The function should find two different numbers in the array that, when added together, give the target number. For example: answer([1,2,3], 4)should return [1,3]
// Question 2: Write a javascript function that takes an array of numbers and a target number. The function should find
// two different numbers in the array that, when added together, give the target number. For example: answer([1,2,3], 4)
// should return [1,3]
function twoSumBest(array, target) {
const numsMap = new Map();
for (let i = 0; i < array.length; i++) {
if(numsMap.has(target - array[i])) {
return [numsMap.get(target - array[i]), i];
@cormac0108
cormac0108 / cleanTheRoom.js
Created July 20, 2020 23:09
ZTM 2020 Clean the room challenge
// 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].
// Bonus: Make it so it organizes strings differently from number types. i.e. [1, "2", "3", 2]
// should return [[1,2], ["2", "3"]]
function clean(arr) {
let i = 0;
let pos = 0;
let duplicateArray = [];