Skip to content

Instantly share code, notes, and snippets.

View anri-asaturov's full-sized avatar

Anri Asaturov anri-asaturov

View GitHub Profile
@anri-asaturov
anri-asaturov / flatten-array.js
Last active January 8, 2018 22:32
Flatten array
// ------------- MODULE -------------------
/**
* Flattens array containing nested arrays into a one-level array.
* @param {Array} arr - array to flatten
* @returns {Array} flat array, always a new instance
*/
function flattenArray(arr) {
if (!Array.isArray(arr)) throw new Error('First argument should be Array.');
// result accumulator
@anri-asaturov
anri-asaturov / blurOnEnter
Last active April 7, 2017 07:53
Angular blur on enter directive
myApp.directive('blurOnEnter', function(){
return {
link: function (scope, element, attrs) {
element.bind("keypress", function (event) {
if(event.which === 13) {
element.blur();
event.preventDefault();
}
});
}