Skip to content

Instantly share code, notes, and snippets.

@stowns
Last active May 16, 2019 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stowns/6efcdb349ebc613d8f44a4772b2a1f6d to your computer and use it in GitHub Desktop.
Save stowns/6efcdb349ebc613d8f44a4772b2a1f6d to your computer and use it in GitHub Desktop.
couple of toy fn's
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]))
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