This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let reliablyTerribleSort = function(unSortedArray) { | |
| let sign = 1; | |
| let flipSignSort = function(a, b) { | |
| sign *= -1; | |
| return a - sign * b; | |
| }; | |
| return unSortedArray.slice().sort(flipSignSort); | |
| }; | |
| let test = [1, 2, 3, 4]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // The permutations function is based off the answer found at | |
| // https://stackoverflow.com/a/17917159 | |
| // Converted to a more ES6 solution. | |
| // Note: permutations will return duplicates, filtering was removed as it seem | |
| // to increase the run time for larger strings. | |
| let permutations = function(string, start = '') { | |
| if (string.length == 1) { | |
| return [string]; | |
| } else { | |
| return string.split('').reduce((acc, l, i, arr) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let baseNotation_raw = function(number, base) { | |
| return new Array(Math.ceil(Math.log(number) / Math.log(base)) + 1) | |
| .fill(0) | |
| .map((v, i) => Math.pow(base, i)) | |
| .reverse() | |
| .reduce((acc, v, i) => { | |
| acc[i] = Math.floor(number / v); | |
| number = number % v; | |
| return acc; | |
| }, []); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let baseNotation_raw = function(number, base) { | |
| return new Array(Math.ceil(Math.log(number) / Math.log(base)) + 1) | |
| .fill(0) | |
| .map((v, i) => Math.pow(base, i)) | |
| .reverse() | |
| .reduce((acc, v, i) => { | |
| acc[i] = Math.floor(number / v); | |
| number = number % v; | |
| return acc; | |
| }, []); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let baseNotation_raw = function(number, base) { | |
| return new Array(Math.ceil(Math.log(number) / Math.log(base)) + 1) | |
| .fill(0) | |
| .map((v, i) => Math.pow(base, i)) | |
| .reverse() | |
| .reduce((acc, v, i) => { | |
| acc[i] = Math.floor(number / v); | |
| number = number % v; | |
| return acc; | |
| }, []); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let reverseWordsInPlace_1 = function(phrase) { | |
| return phrase | |
| .split(/(\W+)/) | |
| .map( | |
| v => | |
| v.match(/\w/) | |
| ? v | |
| .split('') | |
| .reverse() | |
| .join('') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict'; | |
| // Note: The .sort() is doing a string sort and not a numeric sort. If a larger | |
| // number is present and the array is not properly sorted, the array is not the | |
| // match we want. | |
| let iOSSum_1 = function(arr) { | |
| let targetArray = [1, 2, 3]; | |
| if ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Based off of a previous solution | |
| // https://gist.github.com/devNoiseConsulting/81a5d1236d7219f1bcd7dc2161081434 | |
| const readline = require('readline'); | |
| let transposeArray = function(array) { | |
| return array[0].map((col, i) => array.map(row => row[i])); | |
| }; | |
| function transposeText(textArray) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict'; | |
| let returnArtistOverlap = function(artists1, artists2) { | |
| let size = artists1.length - 1; | |
| return artists1.map(v => artists2.indexOf(v)).reduce((acc, v, i) => { | |
| if (v !== -1) { | |
| acc.set(artists1[i], size - v + (size - i)); | |
| } | |
| return acc; | |
| }, new Map()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict'; | |
| let returnOverlap = function(artists1, artists2) { | |
| return artists1.map(v => artists2.indexOf(v)).reduce((acc, v, i) => { | |
| if (v !== -1) { | |
| acc.set(artists1[i], v + i); | |
| } | |
| return acc; | |
| }, new Map()); | |
| }; |