Skip to content

Instantly share code, notes, and snippets.

View ZackFox's full-sized avatar
😎
looking for a job

Сергей ZackFox

😎
looking for a job
View GitHub Profile
/**
* function ListNode(val) {
* this.val = val;
* this.next = null;
* }
*/
var mergeTwoLists = function(l1, l2) {
const dummy = new ListNode(0);
let current = dummy;
var isAnagram = function(s, t) {
if (s === t ) return true;
if (s.length !== t.length) return false;
const map = s.split("").reduce((obj,n) => {
obj[n] = !obj[n] ? 1 : obj[n] + 1;
return obj;
},{});
for(let letter of t){
function indexOf (string, sub) {
if(string === sub || !sub) return 0;
if(!string ) return -1;
let res = -1;
let k = 0;
for(let i = 0 ; i < string.length; i++){
if(string.charAt(i) === sub.charAt(k)){
k++;
// ключевой принцип
// prefix иницилизирован как первое слово
// сравнение символов из prefix с символами каждого слова слова
// если символ не совпадает - перезаписываем префикс и продолжаем
function longestCommonPrefix(strs) {
if(!strs || strs.length === 0 ) return "";
let prefix = strs[0];
for(let j = 1; j < strs.length; j++){
// ключевой принцип
// запись элементов в дополнительный массив
// проверка наличия элемента в массие
function removeDuplicates(nums){
return nums.reduce((acc, n) => {
if(acc.indexOf(n) === -1) {
acc.push(n)
}
return acc;
function isBalanced(s) {
const temp = {
"[": "]",
"(": ")",
"{": "}"
};
const stack = [];
let closed;
Array.prototype.isSorted = function () {
if(this.length < 2) return false;
let dir = this[0] < this[1] ? 1 : -1;
for(let i = 1; i < this.length-1; i++) {
if(dir === 1 && this[i] > this[i+1]) {
return false;
}
if(dir === -1 && this[i] < this[i+1]) {
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
function debounce(func,delay = 200){
let timer = null;
return function(...args){
if(timer){
clearTimeout(timer);
}
timer = setTimeout(() => {
func.apply(null,args)