Skip to content

Instantly share code, notes, and snippets.

View animated-check.js
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 Jan 3, 2018
Sentences capitalization in JavaScript
View sentences_capitalization.js
//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 Jan 3, 2018
Anagrams in JavaScript
View anagrams.js
//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 Jan 3, 2018
Reverse String in JavaScript
View reverse_string.js
//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 Jan 3, 2018
Reverse Int in JavaScript
View reverse_int.js
//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 Jan 3, 2018
Characters Map in JavaScript
View charactermap.js
//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 Jan 3, 2018
FizzBuzz in JavaScript
View fizzbuzz.js
//specs
fizzBuzz(15);
1
2
fizz
4
buzz
fizz
7
8
@eldyvoon
eldyvoon / chunk.js
Last active Jan 3, 2018
Split Chunk Array in JavaScript
View chunk.js
//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 Jan 5, 2018
Step and Pyramic tree in Javascript
View pyramid_tree.js
steps(4);
//
#
##
###
####
pyramid(5)
//
@eldyvoon
eldyvoon / vowels.js
Created Jan 5, 2018
Find vowels in JavaScript
View vowels.js
//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()) {