Last active
April 13, 2017 12:47
-
-
Save ColinFendrick/11b7ed70ac8cc6f2348701cae182613d to your computer and use it in GitHub Desktop.
5 and 6 Kyu solutions
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
const nextBigger = (n) => { | |
d = (''+n).split('') | |
let pivot | |
let numArray | |
let min = 10 | |
let place | |
for (let i = d.length - 2; i >= 0; i--) { | |
if (d[i] < d[i + 1]) { | |
numArray = d.slice(i + 1) | |
pivot = d[i] | |
for (var j = 0; j < numArray.length; j++) { | |
if ((numArray[j] < min) && (numArray[j] > pivot)) { | |
min = numArray[j] | |
place = j | |
} | |
} | |
d.splice(i, 1, min) | |
numArray.splice(place, 1, pivot) | |
return Number(d.slice(0, i + 1).concat(numArray.sort()).join('')) | |
} | |
} | |
return -1 | |
} |
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
// https://www.codewars.com/kata/520b9d2ad5c005041100000f | |
const pigIt = (str) => { | |
return str.split(' ').map((word) => word.substr(1) + word.substr(0, 1) + 'ay').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
// https://www.codewars.com/kata/521c2db8ddc89b9b7a0000c1 | |
const snail = (array) => { | |
let result | |
while (array.length) { | |
result = (result ? result.concat(array.shift()) : array.shift()) | |
for (let i = 0; i < array.length; i++) { | |
result.push(array[i].pop()) | |
} | |
result = result.concat((array.pop() || []).reverse()) | |
for (let i = array.length - 1; i >= 0; i--) { | |
result.push(array[i].shift()) | |
} | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment