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
function solution(A, B) { | |
// write your code in JavaScript (Node.js 8.9.4) | |
if(A.length === 1 ){ | |
return 1; | |
} else if(A.length ===0){ | |
return 0; | |
} | |
let nonOverlapping = 1; | |
let prevEnd = B[0]; |
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
// you can write to stdout for debugging purposes, e.g. | |
// console.log('this is a debug message'); | |
function isOdd(num){return num%2} | |
function solution(S) { | |
let solution = -1; | |
const passwords = S.split(' '); | |
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
function solution(A) { | |
// write your code in JavaScript (Node.js 8.9.4) | |
// set solution and index to 0 | |
let solution = 0; | |
// sort array ascending to make finding the missing one easier | |
A.sort((a,b)=>a-b); | |
let index = 0; | |
while(solution === 0 && index <= A.length ){ | |
solution = (A[index] !== (index+1) )? index+1 : 0; |
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
function calcObjectLength(myObject, size) { | |
Object.entries(myObject).forEach(([, value]) => { | |
if (!isObject(value)) { | |
console.log('+1'); | |
size += 1; | |
} else { | |
console.log('is object'); | |
size += calcObjectLength(value, size); | |
} | |
}); |
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
function solution(N) { | |
// write your code in JavaScript (Node.js 8.9.4) | |
let binaryGaps = (N).toString(2); // returns binary string | |
binaryGaps = binaryGaps.replace(/^0*/,''); // remove leading zeros (no gap) | |
binaryGaps = binaryGaps.replace(/(0*$)/, ''); // remove trailing zeros (no gap) | |
binaryGaps = binaryGaps.split(1); // split on 1 to get gaps | |
const longestGap = Math.max(...(binaryGaps.map(gap => gap.length))); // get maximum number | |
return longestGap; | |
} |
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
/* src/components/Counter/test/Counter.test.js */ | |
import React from 'react' | |
import Counter from '../'; | |
import { shallow } from 'enzyme'; | |
import toJson from 'enzyme-to-json' | |
const callBackFunc = jest.fn(); | |
const counterComponent = shallow(<Counter callBack = {callBackFunc} />); | |
describe('<counterComponent />', () => { |
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
/* src/components/Counter/index.js */ | |
import React from 'react'; | |
import PropTypes from 'prop-types'; | |
import classNames from 'classnames/bind'; | |
import './index.css'; | |
class Counter extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { |
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
describe('Counter', ()=> { | |
const callBackFunc = jest.fn(); | |
const counterComponent = shallow(<Counter callBack = {callBackFunc} />); | |
(...) | |
it('calls a callback function with the current amount', () => { | |
expect(callBackFunc).toHaveBeenCalledTimes(2); | |
expect(callBackFunc).toHaveBeenLastCalledWith(0); | |
}); |
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
decreaseAmount() { | |
this.setState(prevState => ( | |
{amount: prevState.amount -1}) | |
) | |
} |
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
it('decreases the amount on minus interaction', () => { | |
const decreaseFunc = jest.spyOn(Counter.prototype, 'decreaseAmount'); | |
counterComponent.find("[aria-label='decrease']").first().simulate('click'); | |
expect(decreaseFunc).toHaveBeenCalledTimes(1); | |
expect(counterComponent.find("[aria-label='current amount']").first().props().value).toBe(0); | |
}); |