Real Vim ninjas count every keystroke - do you?

Pick a challenge, fire up Vim, and show us what you got.

Changelog, Rules & FAQ, updates: @vimgolf, RSS.

Your VimGolf key: please sign in

$ gem install vimgolf
$ vimgolf setup
$ vimgolf put 58753af0f5ef5c0006000006

Change attribute to getter

Wrap attributes with a getter method.

Start file
function() {
  var a = thing.index < other.attribute;
  var b = thing.index < other.attribute;
  var c = thing.attribute < other.index;
  var d = thing.attribute < other.index;
}
End file
function() {
  var a = thing.get('index') < other.get('attribute');
  var b = thing.get('index') < other.get('attribute');
  var c = thing.get('attribute') < other.get('index');
  var d = thing.get('attribute') < other.get('index');
}

View Diff

2,5c2,5
<   var a = thing.index < other.attribute;
<   var b = thing.index < other.attribute;
<   var c = thing.attribute < other.index;
<   var d = thing.attribute < other.index;
---
>   var a = thing.get('index') < other.get('attribute');
>   var b = thing.get('index') < other.get('attribute');
>   var c = thing.get('attribute') < other.get('index');
>   var d = thing.get('attribute') < other.get('index');

Solutions

The best way to learn is to practice. Below, you will find some of the solutions other golfers have entered. To unlock higher ranked solutions, submit your own entry which does as well or better than the solutions you can currently see - climb the ladder!

Check out these helpful resources to improve your Vim skills... Game on.

Unlock 40 remaining solutions by signing in and submitting your own entry
#41 Matt Walsh / @wattmalsh - Score: 47 - 02/08/17 @ 07:21
:%s/\(thing\|other\)\.\(\a*\)/\1.get('\2')/g<CR>ZZ

0 comments


Created by: @wyne

41 active golfers, 88 entries

Leaderboard (lowest score wins):
25
#31 - Vim Girl / @vim_girl

10/17/2017 at 03:11AM

25
#32 - Norbert / @mullno

07/02/2018 at 06:15PM

25
#33 - albalitz / @_albalitz

06/26/2019 at 02:43PM

26
#34 - Michael Topal / @h4ckt1c

01/27/2017 at 09:14AM

29
#35 - Air Quality Test 8 / @AirQualityTest8

01/15/2017 at 10:14AM

29
#36 - Benoit Bou / @3enoit3

06/18/2017 at 07:30AM

31
#37 - Antoine Leveugle / @Denouche

01/11/2017 at 09:11AM

34
#38 - Yann / @yannstad

02/22/2017 at 06:31AM

37
#39 - Justin Wyne / @wyne

01/10/2017 at 08:05PM

39
#40 - Yongjoo Ji / @msrband

01/12/2017 at 01:36AM

47
#41 - Matt Walsh / @wattmalsh

02/08/2017 at 07:21AM