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
//! Single Number | |
//? Example: | |
// Input: [4,1,2,1,2] | |
// Output: 4 | |
// function singleNumber(nums) { | |
// for (let i = 1; i < nums.length; i++) { | |
// nums[0] ^= nums[i]; | |
// } |
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
// ! Split Strings CODEWARS | |
// //?Solution 1 | |
function solution(str) { | |
return (str.length % 2 ? str + '_' : str).match(/../g); | |
} | |
console.log(solution('abcdef')); // ['ab', 'cd', 'ef'] | |
console.log(solution('abc')); // ['ab', 'c_'] | |
// //?Solution 2 | |
function solution(str) { |
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
// ! Unique In Order CODEWARS | |
//?Solution 1 | |
var uniqueInOrder = function(iterable) { | |
return [].filter.call(iterable, function(a, i) { | |
return iterable[i - 1] !== a; | |
}); | |
}; | |
console.log(uniqueInOrder('AAAABBBCCDAABBB')); // ['A', 'B', 'C', 'D', 'A', 'B'] | |
console.log(uniqueInOrder('ABBCcAD')); // ['A', 'B', 'C', 'c', 'A', 'D'] | |
console.log(uniqueInOrder([1, 2, 2, 3, 3])); // [1,2,3] |
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
// ! Isograms Trolls CODEWARS | |
/** | |
* Изограмма - это слово, которое не имеет повторяющихся букв, последовательных или непоследовательных. | |
*/ | |
// ?Solution 1 | |
function isIsogram(str) { | |
for (let i = 0; i < str.length; i++) { | |
if (str.toLowerCase().split(str[i]).length - 1 > 1) { | |
return false; |
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
// ! Disemvowel Trolls CODEWARS | |
//?Solution 1 | |
function disemvowel(str) { | |
return (str || '').replace(/[aeiou]/gi, ''); | |
} | |
//?Solution 2 | |
function disemvowel(str) { | |
var vowels = ['a', 'e', 'i', 'o', 'u']; |
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
/*** | |
* Throttle Decorator | |
* @type {Element} | |
*/ | |
let realElement = document.querySelector('#real'); | |
let throttleElement = document.querySelector('#throttle'); | |
function onMove(element, event) { |
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
1. Получаем хэш-код коммита, к которому хотим вернуться. | |
2. Заходим в папку репозитория и пишем в консоль: | |
$ git reset --hard a3775a5485af0af20375cedf46112db5f813322a | |
$ git push --force |
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
'use strict'; | |
/** | |
* Реализовать RLE-сжатие: | |
* Функция принимает строку и возвращает новую строку | |
* 2 и больше одинаковых букв стоящих подряд в исходной строке | |
* заменяются на эту букву и число повторений | |
* число 1 не добавляется! | |
* | |
* AAAB -> A3B, BCCDDDAXXXX -> BC2D3AX4 |
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
'use strict'; | |
function isUnique(str) { | |
var i, ch; | |
var len = str.length; | |
if (len > 127) { | |
return false; | |
} |
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
var abc="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split("");//Набор символов который будет использоваться в системе счисления | |
//Перевод числа из любой системы счисления в десятичную | |
function ToNum(a,b){// Аргументы: строка, система счисления | |
var n = 0; | |
var mas = abc.slice(0,b); | |
a = String(a); | |
for(var i = 0;i < a.length;i++){ | |
n = n +(mas.indexOf(a.substr(a.length-i-1,1))*Math.pow(b,i)); | |
} | |
return n; |
NewerOlder