Skip to content

Instantly share code, notes, and snippets.

@eldyvoon
eldyvoon / animated-check.js
Created April 11, 2016 15:58 — forked from tkh44/animated-check.js
Animated Checkmark Directive inspired by http://codepen.io/haniotis/pen/KwvYLO
angular.module('animated-checkmark', []).directive('animatedCheck', animatedCheck);
function animatedCheck() {
const svgTemplate = `
<div class="checkmark-container">
<svg class="checkmark" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52">
<g>
<circle class="checkmark-outline" cx="26" cy="26" r="25" fill="none" />
<circle class="checkmark-circle" cx="26" cy="26" r="25" fill="none" />
<path class="checkmark-check" fill="none" d="M14.1 27.2l7.1 7.2 16.7-16.8" />
</g>
@eldyvoon
eldyvoon / sentences_capitalization.js
Last active January 3, 2018 04:58
Sentences capitalization in JavaScript
//spec
capitalize('my mom is cooking') // My Mom Is Cooking
capitalize('wait, I'm coming!') // Wait I'm Coming!
//solution 1
function capitalize(str) {
const words = [];
for(let word of str.split(' ')){
words.push(word[0].toUpperCase() + word.slice(1))
@eldyvoon
eldyvoon / anagrams.js
Last active January 3, 2018 04:58
Anagrams in JavaScript
//specs
anagrams('rail safety', 'fairy tales') // true
anagrams('RAIL SAFETY', 'fairy tales') // true
anagrams('hi there', 'bye there') // false
//solution 1
function anagrams(strA, strB) {
const charMapA = buildCharMap(strA);
const charMapB = buildCharMap(strB);
@eldyvoon
eldyvoon / reverse_string.js
Last active January 3, 2018 06:58
Reverse String in JavaScript
//specs
reverseString('hello world') //dlrow olleh
//solution 1
function reverseString(str) {
return str.split('').reverse().join('')
}
//solution 2
function reverseString(str){
@eldyvoon
eldyvoon / reverse_int.js
Created January 3, 2018 07:58
Reverse Int in JavaScript
//specs
reverseInt(12); //21
reverseInt(500); //5
reverseInt(-15); //-51
function reverseInt(n) {
const reversed = n.toString().split('').reverse().join('')
return parseInt(reversed) * Math.sign(n)
}
@eldyvoon
eldyvoon / charactermap.js
Last active January 3, 2018 08:24
Characters Map in JavaScript
//specs
const str = 'nice to meet you!';
buildCharMap(str); // {"n":1,"i":1,"c":1,"e":3," ":3,"t":2,"o":2,"m":1,"y":1,"u":1,"!":1}
function buildCharMap(str) {
const char = {};
for(let character of str) {
char[character] = char[character] && char[character] + 1 || 1;
}
return char;
@eldyvoon
eldyvoon / fizzbuzz.js
Last active January 3, 2018 08:31
FizzBuzz in JavaScript
//specs
fizzBuzz(15);
1
2
fizz
4
buzz
fizz
7
8
@eldyvoon
eldyvoon / chunk.js
Last active January 3, 2018 09:23
Split Chunk Array in JavaScript
//specs
chunk([1,2,3,4], 2) // [[1,2][3,4]]
chunk([1,2,3,4,5], 2) // [[1,2],[3,4],[5]]
chunk([1,2,3,4,5], 10) // [[1,2,3,4,5]]
//solution 1
function chunk(array, size) {
const chunked = [];
@eldyvoon
eldyvoon / pyramid_tree.js
Last active January 5, 2018 02:55
Step and Pyramic tree in Javascript
steps(4);
//
#
##
###
####
pyramid(5)
//
@eldyvoon
eldyvoon / vowels.js
Created January 5, 2018 03:29
Find vowels in JavaScript
//specs
vowels('Hello World!') //3
vowels('My name is javascript') //6
//solution 1
function vowels(str) {
const vowelChar = ['a', 'e', 'i', 'o', 'u'];
let count = 0;
for (let char of str.toLowerCase()) {