Skip to content

Instantly share code, notes, and snippets.

const smallestDivisor = (num) => {
const iter = (acc) => {
// We use 'num / 2' in the condition below, and not 'num'.
// This is a simple optimization: a number cannot be divided
// by a number larger than its half.
if (acc > num / 2) {
return num;
}
if (num % acc === 0) {
return acc;
import { length } from './strings'; // eslint-disable-line
// BEGIN (write your solution here)
const sum = (str) => {
let result = 0;
for(let i = 0; i < length(str); i++) {
result += Number(str[i]);
}
// BEGIN (write your solution here)
const smallestDivisor = num => {
let divisor = 2;
if(num < 1) {
return NaN;
}
if(num === 1) {
return num;
import { length, toUpperCase } from './strings';
// BEGIN (write your solution here)
export default (str) => {
let result = "";
for(let i = 0; i < length(str); i++) {
const shouldBeBig = str[i] !== " " && (i === 0 || str[i - 1] === " ");
result += shouldBeBig ? toUpperCase(str[i]) : str[i];
}
@Lodo4ka
Lodo4ka / get key nested object
Created March 22, 2020 15:09
get key nested object any depths
const getIn = (data, keys) => {
let current = data;
for (const key of keys) {
if (!has(current, key)) {
return null;
}
current = current[key];
}
return current;
compareObject(objOne, objTwo) {
return Object.keys(objTwo).every(
key => objOne.hasOwnProperty(key) && objOne[key] == objTwo[key]
);
},
@Lodo4ka
Lodo4ka / launch.json
Created December 11, 2019 12:18
debuging mocha in vs code from node js
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Mocha All",
{
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.detectIndentation": false,
"editor.formatOnSave": false,
// "css.fileExtensions": [
// "css",
// "scss",
// "less"
// ],
@Lodo4ka
Lodo4ka / best filter for date in client JS
Created September 27, 2019 10:34
filter from course node
capitalize(value) {
return (
value
.toString()
.charAt(0)
.toUpperCase() + value.slice(1)
);
},
date(value) {
return new Intl.DateTimeFormat('ru-RU', {
@Lodo4ka
Lodo4ka / app.js
Created September 27, 2019 10:25
return new Intl.DateTimeFormat('ru-RU', {
year: 'numeric',
month: 'long',
day: '2-digit',
}).format(new Date(value));