Last active
May 16, 2019 19:33
-
-
Save stowns/6efcdb349ebc613d8f44a4772b2a1f6d to your computer and use it in GitHub Desktop.
couple of toy fn's
This file contains 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
function oddOccurences(arr) { | |
let odds = []; | |
let previous; | |
let count = 0; | |
for (let i = 0; i < arr.length; i++) { | |
let current = arr[i]; | |
if (!previous) { | |
previous = current; | |
} | |
if (previous === current) { | |
count++; | |
} else { | |
if (count % 2 !== 0) { | |
odds.push(previous); | |
} | |
count = 1 | |
} | |
previous = current; | |
} | |
return odds; | |
} | |
console.log(oddOccurences([1,2,2,2,2,3,3,3,4,5,5])) |
This file contains 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
function reverseCheating(str) { | |
return str.split('').reverse().join('') | |
} | |
console.log(reverseCheating('testing123')) | |
function reverse(str) { | |
let arr = str.split(''); | |
let reversed = '' | |
for (let i = arr.length; i > 0; i--) { | |
reversed += arr[i-1]; | |
} | |
return reversed | |
} | |
console.log(reverse('testing123')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment