Skip to content

Instantly share code, notes, and snippets.

View jeanlescure's full-sized avatar
🚀
Actively Contributing

Jean Lescure jeanlescure

🚀
Actively Contributing
View GitHub Profile
@jeanlescure
jeanlescure / TapeEquilibrium.js
Last active September 2, 2022 13:57
Codility TapeEquilibrium Solution in Javascript - 100% score
/*
A non-empty zero-indexed array A consisting of N integers is given. Array A represents numbers on a tape.
Any integer P, such that 0 < P < N, splits this tape into two non-empty parts: A[0], A[1], ..., A[P − 1] and A[P], A[P + 1], ..., A[N − 1].
The difference between the two parts is the value of: |(A[0] + A[1] + ... + A[P − 1]) − (A[P] + A[P + 1] + ... + A[N − 1])|
In other words, it is the absolute difference between the sum of the first part and the sum of the second part.
*/
@jeanlescure
jeanlescure / Equi.js
Created September 18, 2015 09:02
Codility Equi Solution in Javascript - 100% score
/*
A zero-indexed array A consisting of N integers is given. An equilibrium index of this array is any integer P such that 0 ≤ P < N and the sum of elements of lower indices is equal to the sum of elements of higher indices, i.e.
A[0] + A[1] + ... + A[P−1] = A[P+1] + ... + A[N−2] + A[N−1].
Sum of zero elements is assumed to be equal to 0. This can happen if P = 0 or if P = N−1.
*/
function solution(A) {
var sum = A.reduce(function(pv, cv) { return pv + cv; });
@jeanlescure
jeanlescure / MaxCounters.js
Last active September 18, 2015 11:49
Codility MaxCounters Solution in Javascript - 66% score
/*
You are given N counters, initially set to 0, and you have two possible operations on them:
• increase(X) − counter X is increased by 1,
• max counter − all counters are set to the maximum value of any counter.
A non-empty zero-indexed array A of M integers is given. This array represents consecutive operations:
• if A[K] = X, such that 1 ≤ X ≤ N, then operation K is increase(X),
• if A[K] = N + 1 then operation K is max counter.
@jeanlescure
jeanlescure / MaxCountersOptimized.js
Last active September 24, 2022 17:51
Codility MaxCounters Solution Javascript - 100% score
/*
You are given N counters, initially set to 0, and you have two possible operations on them:
• increase(X) − counter X is increased by 1,
• max counter − all counters are set to the maximum value of any counter.
A non-empty zero-indexed array A of M integers is given. This array represents consecutive operations:
• if A[K] = X, such that 1 ≤ X ≤ N, then operation K is increase(X),
• if A[K] = N + 1 then operation K is max counter.

Number Prettifier NodeJS Package

(This README is written using Markdown notation, for better viewing visit: https://goo.gl/aIEm4Y)

This is my submission for the Crossover Tech Trial. A NodeJS package which can be used to extend back-end and front-end applications alike with the ability to transform number types less than a Quadrillion in the short scale to prettified strings.

The package includes two demo files, one for back-end (using NodeJS) and another for front-end (browser).

Requirements - Back-end

@jeanlescure
jeanlescure / ReactApp.jsx
Created September 30, 2015 10:21
Using Semantic UI Modal in a React.js App
var HelloModal = React.createClass({
getInitialState: function() {
return {
visible: false
};
},
componentDidMount: function() {
var self = this;
$(window).on('modal.visible', function(ev){
self.setState({visible: true});
@interface ViewController ()
<OTSessionDelegate, OTSubscriberKitDelegate, OTPublisherDelegate>
@end
@jeanlescure
jeanlescure / DB_Limit_Items.psql
Created December 11, 2015 13:31
For PostgreSQL. Limit amount of items in a table to N number of items and destroy excess as well as re-index remanent.
/*
* For PostgreSQL
* Limit amount of items in a table to N number of items and destroy
* excess as well as re-index remanent.
*/
SELECT pg_size_pretty(pg_total_relation_size('items')) AS items_size;
DELETE FROM items
WHERE id <= (
!xrdb .Xdefaults
*xterm*initialFont:5
!*xterm*font: -*-terminus-*-*-*-56-*-*-*-*-*-*-*
!*xterm*faceSize: 56
! terminal colours
*xterm*foreground:#CCCCCC
*xterm*background:#1B1D1E
def get_products_of_all_ints_except_at_index arr
arr.map do |i|
filtered = arr.select do |j|
i != j
end
filtered.reject(&:zero?).inject(:*)
end
end