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
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; |
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
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]); | |
} | |
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
// BEGIN (write your solution here) | |
const smallestDivisor = num => { | |
let divisor = 2; | |
if(num < 1) { | |
return NaN; | |
} | |
if(num === 1) { | |
return num; |
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
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]; | |
} |
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
const getIn = (data, keys) => { | |
let current = data; | |
for (const key of keys) { | |
if (!has(current, key)) { | |
return null; | |
} | |
current = current[key]; | |
} | |
return current; |
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
compareObject(objOne, objTwo) { | |
return Object.keys(objTwo).every( | |
key => objOne.hasOwnProperty(key) && objOne[key] == objTwo[key] | |
); | |
}, |
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 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", |
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
{ | |
"editor.tabSize": 2, | |
"editor.insertSpaces": true, | |
"editor.detectIndentation": false, | |
"editor.formatOnSave": false, | |
// "css.fileExtensions": [ | |
// "css", | |
// "scss", | |
// "less" | |
// ], |
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
capitalize(value) { | |
return ( | |
value | |
.toString() | |
.charAt(0) | |
.toUpperCase() + value.slice(1) | |
); | |
}, | |
date(value) { | |
return new Intl.DateTimeFormat('ru-RU', { |
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
return new Intl.DateTimeFormat('ru-RU', { | |
year: 'numeric', | |
month: 'long', | |
day: '2-digit', | |
}).format(new Date(value)); |
NewerOlder