Skip to content

Instantly share code, notes, and snippets.

Kathrin Holzmann Lelith

  • Berlin
Block or report user

Report or block Lelith

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Lelith
Lelith / tieRopes.js
Created Mar 12, 2020
tie ropes together
View tieRopes.js
function solution(K, A) {
let ropes = 0;
let length = 0;
A.forEach(rope => {
length += rope;
if(length >=K){
ropes +=1;
length = 0;
@Lelith
Lelith / greedyalgorithm.js
Created Mar 12, 2020
non overlapping segments
View greedyalgorithm.js
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];
@Lelith
Lelith / longest password
Created Mar 11, 2020
longest password (60% solution, i tought needs to contain characters AND numbers)
View longest password
// 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(' ');
@Lelith
Lelith / MissingNumber
Last active Mar 11, 2020
Find missing number runtime: O(N) or O(n*long(n))
View MissingNumber
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;
@Lelith
Lelith / index.js
Created Mar 10, 2020
calculate object entries with recursion
View index.js
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);
}
});
@Lelith
Lelith / binaryGap.js
Created Mar 7, 2020
binary gap solution
View binaryGap.js
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;
}
View snapshot.test.js
import React from 'react'
import MyComponent from '../';
import toJson from 'enzyme-to-json'
describe('<Component />', () => {
it('should match the snapshot', () => {
const MyComponentWrapper = mount(<MyComponent />)
expect(toJson(MyComponentWrapper)).toMatchSnapshot()
})
})
@Lelith
Lelith / counter.js
Created Feb 14, 2020
Call callback in componentDidUpdate
View counter.js
/* 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 = {
View counter.test.js
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);
});
@Lelith
Lelith / counter.js
Created Feb 14, 2020
Decrease amount function
View counter.js
decreaseAmount() {
this.setState(prevState => (
{amount: prevState.amount -1})
)
}
You can’t perform that action at this time.