Skip to content

Instantly share code, notes, and snippets.

View benvds's full-sized avatar
😀

Ben van de Sande benvds

😀
View GitHub Profile
/**
* Returns a number from a given string. It ignores any characters, including
* comma's and points. When more than 1 number is found in a string, the last
* number is used as the fractional of the number. For example:
*
* '€ 12,34' => 12.34
* '1,234.567 %' => 1234.567
*
* @argument {string} text - text containing the number or number parts
* @returns {number|undefined} - parsed number or undefined when none found
@benvds
benvds / array_ordering.rb
Last active June 14, 2017 10:26
Move an array item to specified index
module ArrayOrdering
# Returns clone of the array with subject moved into the new idx
def self.move_to_position(_list, subject, new_idx)
old_idx = _list.index(subject)
return _list unless old_idx != new_idx
list = _list.clone
if old_idx.nil?
-- Based on:
--
-- - https://github.com/mjlbach/defaults.nvim
-- - https://github.com/shift-d/nv/
-- - https://github.com/NvChad/NvChad
-- Sane defaults
[
{
"name":"Afghanistan",
"code":"AF"
},
{
"name":"Åland Islands",
"code":"AX"
},
{