lodashSandbox: drop

ES6 Enabled

by David McClelland

HTML

<script src="https://cdn.jsdelivr.net/npm/[email protected]/lodash.min.js"></script>
<div class="wrapper">
  <div class="title">
    <h3>
      _.drop
    </h3>
  </div>
  <div class="subtitle">
    <h4>
      Remove <i>n</i> elements from start of array (or end is dropRight)
    </h4>
  </div>
  <div class="workspace">
    <input id='startInput' type='text' value="[0, 1, false, 2, 3]" />
    <label for="startInput">array</label>
    <br />
    <input id='modValInput' type='text' value='2' />
    <label for="modValInput">Integer</label>
    <br />
    <button id="button1">drop</button>
    <button id="button2">dropRight</button>
    <br />
    <input id="output" type="text" value="output" />
  </div>
</div>

CSS

label {
  font-size: 12px;
}

.wrapper {
  display: flex;
  flex-direction: column;
}

.title, .subtitle, label {
  font-family: Helvetica;
  color: gray;
}

.workspace {
  display: flex;
  flex-direction: column;
  width: 200px;
}

#output {
  font-family: Courier;
  font-size: 14px;
}

#input1, #input2 {
  font-family: Courier;
  font-size: 14px;
}

#modValInput {
  font-family: Courier;
  font-size: 14px;
}

Babel + JSX

// find elements
let banner = document.getElementById("#playground");
let button = document.getElementById("button");
let modValInput = document.getElementById('modValInput');
let startInput = document.getElementById('startInput');
let output = document.getElementById("output");

button1.onclick = () => {
  doOperation1();
}

button2.onclick = () => {
  doOperation2();
}

function doOperation1() {
	let inputVal = JSON.parse(startInput.value);
  output.value = _.drop(inputVal, modValInput.value);
}

function doOperation2() {
	let inputVal = JSON.parse(startInput.value);
  output.value = _.dropRight(inputVal, modValInput.value);
}